Class: Rack::Cache::MetaStore::Redis

Inherits:
RedisBase show all
Defined in:
lib/rack/cache/redis_metastore.rb

Constant Summary

Constants inherited from Rack::Cache::MetaStore

REDIS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from RedisBase

resolve

Constructor Details

#initialize(server, options = {}) ⇒ Redis

Returns a new instance of Redis


25
26
27
# File 'lib/rack/cache/redis_metastore.rb', line 25

def initialize(server, options = {})
  @cache = ::Redis::Store::Factory.create(server)
end

Instance Attribute Details

#cacheObject (readonly)

The Redis instance used to communicated with the Redis daemon.


23
24
25
# File 'lib/rack/cache/redis_metastore.rb', line 23

def cache
  @cache
end

Instance Method Details

#purge(key) ⇒ Object


38
39
40
41
# File 'lib/rack/cache/redis_metastore.rb', line 38

def purge(key)
  cache.del(hexdigest(key))
  nil
end

#read(key) ⇒ Object


29
30
31
# File 'lib/rack/cache/redis_metastore.rb', line 29

def read(key)
  cache.get(hexdigest(key)) || []
end

#write(key, entries, ttl = 0) ⇒ Object


33
34
35
36
# File 'lib/rack/cache/redis_metastore.rb', line 33

def write(key, entries, ttl=0)
  ttl = ::Redis::Rack::Cache::DEFAULT_TTL if ttl.zero?
  cache.setex(hexdigest(key), ttl, entries)
end