Class: MetalArchives::Cache::Redis
- Defined in:
- lib/metal_archives/cache/redis.rb
Overview
Redis-backed cache
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #clear ⇒ Object
- #delete(key) ⇒ Object
- #include?(key) ⇒ Boolean
-
#initialize(options = {}) ⇒ Redis
constructor
A new instance of Redis.
Methods inherited from Base
Constructor Details
#initialize(options = {}) ⇒ Redis
Returns a new instance of Redis.
11 12 13 14 15 16 |
# File 'lib/metal_archives/cache/redis.rb', line 11 def initialize( = {}) super # Default TTL is 1 month [:ttl] ||= (30 * 24 * 60 * 60) end |
Instance Method Details
#[](key) ⇒ Object
18 19 20 |
# File 'lib/metal_archives/cache/redis.rb', line 18 def [](key) redis.get cache_key_for(key) end |
#[]=(key, value) ⇒ Object
22 23 24 |
# File 'lib/metal_archives/cache/redis.rb', line 22 def []=(key, value) redis.set cache_key_for(key), value, ex: [:ttl] end |
#clear ⇒ Object
26 27 28 |
# File 'lib/metal_archives/cache/redis.rb', line 26 def clear redis.keys(cache_key_for("*")).each { |key| redis.del key } end |
#delete(key) ⇒ Object
34 35 36 |
# File 'lib/metal_archives/cache/redis.rb', line 34 def delete(key) redis.del cache_key_for(key) end |
#include?(key) ⇒ Boolean
30 31 32 |
# File 'lib/metal_archives/cache/redis.rb', line 30 def include?(key) redis.exists? cache_key_for(key) end |