Class: Rack::Cache::EntityStore::Redis

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

Constant Summary

Constants inherited from Rack::Cache::EntityStore

REDIS

Instance Attribute Summary

Attributes inherited from RedisBase

#cache

Instance Method Summary collapse

Methods inherited from RedisBase

#open, resolve

Constructor Details

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

Returns a new instance of Redis.



24
25
26
# File 'lib/rack/cache/redis_entitystore.rb', line 24

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

Instance Method Details

#exist?(key) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/rack/cache/redis_entitystore.rb', line 28

def exist?(key)
  cache.exists key
end

#purge(key) ⇒ Object



42
43
44
45
# File 'lib/rack/cache/redis_entitystore.rb', line 42

def purge(key)
  cache.del key
  nil
end

#read(key) ⇒ Object



32
33
34
# File 'lib/rack/cache/redis_entitystore.rb', line 32

def read(key)
  cache.get key
end

#write(body) ⇒ Object



36
37
38
39
40
# File 'lib/rack/cache/redis_entitystore.rb', line 36

def write(body)
  buf = StringIO.new
  key, size = slurp(body){|part| buf.write(part) }
  [key, size] if cache.set(key, buf.string)
end