class ActiveEndpoint::Routes::Cache::Proxy::RedisStoreProxy

Public Class Methods

new() click to toggle source
# File lib/active_endpoint/routes/cache/proxy/redis_store_proxy.rb, line 6
def initialize
  @prefix = ActiveEndpoint.cache_prefix
  @store = ::Redis::Store.new
end

Public Instance Methods

expires_in(unprefixed_key) click to toggle source
# File lib/active_endpoint/routes/cache/proxy/redis_store_proxy.rb, line 27
def expires_in(unprefixed_key)
  time = @store.ttl(store_key(unprefixed_key)).to_i
  time == -1 || time == -2 ? 0 : time
end
read(unprefixed_key) click to toggle source
# File lib/active_endpoint/routes/cache/proxy/redis_store_proxy.rb, line 11
def read(unprefixed_key)
  @store.get("#{@prefix}:#{unprefixed_key}")
end
write(unprefixed_key, value, expires_in = nil) click to toggle source
# File lib/active_endpoint/routes/cache/proxy/redis_store_proxy.rb, line 15
def write(unprefixed_key, value, expires_in = nil)
  store_key = store_key(unprefixed_key)

  if expires_in.present?
    @store.setex(store_key, expires_in, value)
  else
    @store.set(store_key, value)
  end

  true
end

Private Instance Methods

store_key(unprefixed_key) click to toggle source
# File lib/active_endpoint/routes/cache/proxy/redis_store_proxy.rb, line 34
def store_key(unprefixed_key)
  "#{@prefix}:#{unprefixed_key}"
end