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

Inherits:
Rack::Cache::EntityStore show all
Includes:
RedisBase
Defined in:
lib/rack/cache/redis_entitystore.rb

Constant Summary collapse

MINIMUM_COMPRESSION_BYTESIZE =
1_000

Constants inherited from Rack::Cache::EntityStore

REDIS

Instance Method Summary collapse

Methods included from RedisBase

included, #initialize, #open

Instance Method Details

#exist?(key) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/rack/cache/redis_entitystore.rb', line 15

def exist?(key)
  cache.exists key
end

#purge(key) ⇒ Object



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

def purge(key)
  cache.del key
  nil
end

#read(key) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/rack/cache/redis_entitystore.rb', line 19

def read(key)
  raw = cache.get(key)

  return if raw.nil?

  decompress(raw).force_encoding('utf-8')
end

#write(body, ttl = 0) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/rack/cache/redis_entitystore.rb', line 27

def write(body, ttl=0)
  buf = StringIO.new
  key, size = slurp(body) {|part| buf.write(part) }
  ttl = ttl.to_i.zero? ? default_ttl : ttl
  value = compress(buf.string)

  return unless cache.setex(key, ttl, value)

  [key, size]
end