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



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

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

Instance Method Details

#exist?(key) ⇒ Boolean



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

def exist?(key)
  cache.exists key
end

#purge(key) ⇒ Object



44
45
46
47
# File 'lib/rack/cache/redis_entitystore.rb', line 44

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, ttl = 0) ⇒ Object



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

def write(body, ttl=0)
  buf = StringIO.new
  key, size = slurp(body){|part| buf.write(part) }

  ttl = ::Redis::Rack::Cache::DEFAULT_TTL if ttl.zero?
  [key, size] if cache.setex(key, ttl, buf.string)
end