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