lib/rack/cache/context.rb in rtomayko-rack-cache-0.3.9 vs lib/rack/cache/context.rb in rtomayko-rack-cache-0.4
- old
+ new
@@ -13,15 +13,16 @@
attr_reader :trace
# The Rack application object immediately downstream.
attr_reader :backend
- def initialize(backend, options={}, &block)
+ def initialize(backend, options={})
@backend = backend
@trace = []
+
initialize_options options
- instance_eval(&block) if block_given?
+ yield self if block_given?
@private_header_keys =
private_headers.map { |name| "HTTP_#{name.upcase.tr('-', '_')}" }
end
@@ -107,11 +108,11 @@
end
# Whether the cache entry is "fresh enough" to satisfy the request.
def fresh_enough?(entry)
if entry.fresh?
- if max_age = @request.cache_control.max_age
+ if allow_revalidate? && max_age = @request.cache_control.max_age
max_age > 0 && max_age >= entry.age
else
true
end
end
@@ -141,10 +142,10 @@
# found and is fresh, use it as the response without forwarding any
# request to the backend. When a matching cache entry is found but is
# stale, attempt to #validate the entry with the backend using conditional
# GET. When no matching cache entry is found, trigger #miss processing.
def lookup
- if @request.no_cache?
+ if @request.no_cache? && allow_reload?
record :reload
fetch
elsif entry = metastore.lookup(@request, entitystore)
if fresh_enough?(entry)
record :fresh