https://github.com/jonathanwthom/cream
Simple in-memory Ruby cache.
https://github.com/jonathanwthom/cream
Last synced: 10 months ago
JSON representation
Simple in-memory Ruby cache.
- Host: GitHub
- URL: https://github.com/jonathanwthom/cream
- Owner: JonathanWThom
- License: mit
- Created: 2019-02-07T16:25:16.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-02-08T07:01:43.000Z (over 7 years ago)
- Last Synced: 2025-08-20T18:12:50.031Z (11 months ago)
- Language: Ruby
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# C.R.E.A.M.
Cache Rules Everything Around Me.
Simple in-memory Ruby cache. Inspired by [go-cache](https://github.com/patrickmn/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=>#}
cache.duration_seconds
=> 10
```
### TODO
* Make it into a gem!
* Another test case or two.
### License
MIT