Skip to content
Closed
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
32 changes: 21 additions & 11 deletions lib/rack/cache/metastore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ def store(request, response, entity_store)
headers.delete 'Age'

entries.unshift [stored_env, headers]
write key, entries
if request.env['rack-cache.use_native_ttl'] && response.fresh?
write key, entries, response.ttl
else
write key, entries
end
key
end

Expand All @@ -105,7 +109,13 @@ def invalidate(request, entity_store)
[req, res]
end
end
write key, entries if modified
if modified
if request.env['rack-cache.use_native_ttl'] && response.fresh?
write key, entries, response.ttl
else
write key, entries
end
end
end

private
Expand Down Expand Up @@ -154,7 +164,7 @@ def read(key)
# Store an Array of request/response pairs for the given key. Concrete
# implementations should not attempt to filter or concatenate the
# list in any way.
def write(key, negotiations)
def write(key, negotiations, ttl=nil)
raise NotImplemented
end

Expand Down Expand Up @@ -187,7 +197,7 @@ def read(key)
end
end

def write(key, entries)
def write(key, entries, ttl=nil)
@hash[key] = Marshal.dump(entries)
end

Expand Down Expand Up @@ -225,7 +235,7 @@ def read(key)
[]
end

def write(key, entries)
def write(key, entries, ttl=nil)
tries = 0
begin
path = key_path(key)
Expand Down Expand Up @@ -324,9 +334,9 @@ def read(key)
cache.get(key) || []
end

def write(key, entries)
def write(key, entries, ttl=nil)
key = hexdigest(key)
cache.set(key, entries)
cache.set(key, entries, ttl)
end

def purge(key)
Expand Down Expand Up @@ -358,9 +368,9 @@ def read(key)
[]
end

def write(key, entries)
def write(key, entries, ttl=nil)
key = hexdigest(key)
cache.set(key, entries)
cache.set(key, entries, ttl)
end

def purge(key)
Expand Down Expand Up @@ -393,9 +403,9 @@ def read(key)
cache.get(key) || []
end

def write(key, entries)
def write(key, entries, ttl=nil)
key = hexdigest(key)
cache.put(key, entries)
cache.put(key, entries, ttl)
end

def purge(key)
Expand Down
4 changes: 2 additions & 2 deletions rack-cache.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=

s.name = 'rack-cache'
s.version = '1.2'
s.date = '2012-03-05'
s.version = '1.2.1'
s.date = '2012-10-30'

s.summary = "HTTP Caching for Rack"
s.description = "Rack::Cache is suitable as a quick drop-in component to enable HTTP caching for Rack-based applications that produce freshness (Expires, Cache-Control) and/or validation (Last-Modified, ETag) information."
Expand Down