class Flipper::Adapters::RedisCache
Public: Adapter that wraps another adapter with the ability to cache adapter calls in Redis
.
Public Class Methods
new(adapter, cache, ttl = 3600, prefix: nil)
click to toggle source
Calls superclass method
# File lib/flipper/adapters/redis_cache.rb, line 10 def initialize(adapter, cache, ttl = 3600, prefix: nil) super end
Private Instance Methods
cache_delete(key)
click to toggle source
# File lib/flipper/adapters/redis_cache.rb, line 41 def cache_delete(key) @cache.del(key) end
cache_fetch(key) { || ... }
click to toggle source
# File lib/flipper/adapters/redis_cache.rb, line 16 def cache_fetch(key, &block) cached = @cache.get(key) if cached Marshal.load(cached) else to_cache = yield cache_write key, to_cache to_cache end end
cache_read_multi(keys)
click to toggle source
# File lib/flipper/adapters/redis_cache.rb, line 27 def cache_read_multi(keys) return {} if keys.empty? values = @cache.mget(*keys).map do |value| value ? Marshal.load(value) : nil end Hash[keys.zip(values)] end
cache_write(key, value)
click to toggle source
# File lib/flipper/adapters/redis_cache.rb, line 37 def cache_write(key, value) @cache.setex(key, @ttl, Marshal.dump(value)) end