diff --git a/lib/rack/cache/metastore.rb b/lib/rack/cache/metastore.rb index 2eb56d1..011401d 100644 --- a/lib/rack/cache/metastore.rb +++ b/lib/rack/cache/metastore.rb @@ -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 @@ -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 @@ -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 @@ -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 @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/rack-cache.gemspec b/rack-cache.gemspec index d2b67c9..1df75bf 100644 --- a/rack-cache.gemspec +++ b/rack-cache.gemspec @@ -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."