Skip to content

Instantly share code, notes, and snippets.

@svenfuchs
Created September 13, 2009 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save svenfuchs/186264 to your computer and use it in GitHub Desktop.
Save svenfuchs/186264 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment