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: 6 additions & 2 deletions lib/rack/cache/redis_metastore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ def read(key)
cache.get(hexdigest(key)) || []
end

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

def purge(key)
Expand Down
9 changes: 8 additions & 1 deletion test/rack/cache/metastore/redis_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ def self.call(request); request.path_info.reverse end
store_simple_entry('/bad', { 'SOME_THING' => Proc.new {} })
end

it 'takes a ttl parameter for #write' do
@store.write('/foo', [[{},{}]], 123)
data = @store.read('/foo')
data.must_equal([[{},{}]])
end


# Abstract methods ===========================================================

it 'stores a cache entry' do
Expand Down Expand Up @@ -266,4 +273,4 @@ def self.call(request); request.path_info.reverse end
define_method :uri do |uri|
URI.parse uri
end
end
end