Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions lib/rack/cache/redis_entitystore.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'rack/cache/entitystore'
require 'redis-rack-cache/constants'

module Rack
module Cache
Expand Down Expand Up @@ -36,11 +37,8 @@ def write(body, ttl=0)
buf = StringIO.new
key, size = slurp(body){|part| buf.write(part) }

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

def purge(key)
Expand Down
8 changes: 3 additions & 5 deletions lib/rack/cache/redis_metastore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'rack/utils'
require 'rack/cache/key'
require 'rack/cache/metastore'
require 'redis-rack-cache/constants'

module Rack
module Cache
Expand Down Expand Up @@ -30,11 +31,8 @@ def read(key)
end

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

def purge(key)
Expand Down
7 changes: 7 additions & 0 deletions lib/redis-rack-cache/constants.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Redis
module Rack
module Cache
DEFAULT_TTL = 86_400 * 365 # 1 year
end
end
end