Project

ruby_cream

0.0
No commit activity in last 3 years
No release in over 3 years
Simple in-memory Ruby cache
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.17.2
~> 5.11.3
~> 10.0
 Project Readme

C.R.E.A.M.

Cache Rules Everything Around Me.

Simple in-memory Ruby cache. Inspired by go-cache.

This project is a WIP!

Usage

# Create a new cache instance with item duration in seconds as the argument:
cache = Cache.new(10)

# Set a cache value:
cache.set(:test, "result")

# Get a cache value:
cache.get(:test)
=> "result"

# After some time as has passed, the item will expire:
cache.get(:test)
=> nil

# Reset a key. Time to expiration will reset.
cache.set(:test, "original")
cache.set(:test, "reset")
cache.get(:test)
=> "reset"

# Cache#items and Cache#duration_seconds are both publicly readable for debugging.
cache.items
=> {:test=>#<CacheItem:0x00007ffac103f4d0 @value="result", @expires_at=2019-02-07 08:24:57 -0800>}

cache.duration_seconds
=> 10

TODO

  • Make it into a gem!
  • Another test case or two.

License

MIT