option_accessor :client_ttl
def call!(env)
@trace = []
@env = options.merge(env)
@request = Request.new(@env.dup.freeze)
response =
if @request.get? || @request.head?
if !@env['HTTP_EXPECT']
lookup
else
pass
end
else
invalidate
end
# log trace and set X-Rack-Cache tracing header
trace = @trace.join(', ')
response.headers['X-Rack-Cache'] = trace
# write log message to rack.errors
if verbose?
message = "cache: [%s %s] %s\n" %
[@request.request_method, @request.fullpath, trace]
@env['rack.errors'].write(message)
end
# tidy up response a bit
response.not_modified! if not_modified?(response)
response.client_ttl = self.client_ttl
response.body = [] if @request.head?
response.to_a
end