Caché
A key/value store where pairs can expire after a specified interval
Installation
Add this to your application's shard.yml
:
dependencies:
cache:
github: mamantoha/cache
Usage
Available stores
- [x] Memory
- [x] Redis
- [ ] Memcached (#2)
require "cache"
Memory
# Set all values to expire after one minute.
cache = Cache::MemoryStore(String, String).new(expires_in: 1.minute)
cache.fetch("today") do
Time.now.day_of_week
end
Redis
# Set all values to expire after one minute.
cache = Cache::RedisStore(String, String).new(expires_in: 1.minute)
cache.fetch("today") do
Time.now.day_of_week
end
This assumes Redis was started with a default configuration, and is listening on localhost, port 6379.
You can connect to Redis
by instantiating the Redis class.
If you need to connect to a remote server or a different port, try:
redis = Redis.new(host: "10.0.1.1", port: 6380, password: "my-secret-pw", database: "my-database")
cache = Cache::RedisStore(String, String).new(expires_in: 1.minute, cache: redis)
Contributing
- Fork it ( https://github.com/mamantoha/cache/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
Contributors
- mamantoha Anton Maminov - creator, maintainer