Implements Rack's middleware interface and provides the context for all cache logic, including the core logic engine.
The Rack application object immediately downstream.
Array of trace Symbols
# File lib/rack/cache/context.rb, line 18 def initialize(backend, options={}) @backend = backend @trace = [] @env = nil initialize_options options yield self if block_given? @private_header_keys = private_headers.map { |name| "HTTP_#{name.upcase.tr('-', '_')}" } end
The Rack call interface. The receiver acts as
a prototype and runs each request in a dup object unless the
rack.run_once
variable is set in the environment.
# File lib/rack/cache/context.rb, line 47 def call(env) if env['rack.run_once'] call! env else clone.call! env end end
The real Rack call interface. The caching logic is performed within the context of the receiver.
# File lib/rack/cache/context.rb, line 57 def call!(env) @trace = [] @default_options.each { |k,v| env[k] ||= v } @env = env @request = Request.new(@env.dup.freeze) response = if @request.get? || @request.head? if !@env['HTTP_EXPECT'] && !@env['rack-cache.force-pass'] 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 if (@request.get? || @request.head?) && not_modified?(response) response.not_modified! end if @request.head? response.body.close if response.body.respond_to?(:close) response.body = [] end response.to_a end
The configured EntityStore instance. Changing the rack-cache.entitystore value effects the result of this method immediately.
# File lib/rack/cache/context.rb, line 39 def entitystore uri = options['rack-cache.entitystore'] storage.resolve_entitystore_uri(uri) end
The configured MetaStore instance. Changing the rack-cache.metastore value effects the result of this method immediately.
# File lib/rack/cache/context.rb, line 32 def metastore uri = options['rack-cache.metastore'] storage.resolve_metastore_uri(uri) end