class Rack::Cache::Context
Implements Rack’s middleware interface and provides the context for all cache logic, including the core logic engine.
Attributes
The Rack application object immediately downstream.
Array of trace Symbols
Public Class Methods
Source
# File lib/rack/cache/context.rb, line 18 def initialize(backend, options={}) @backend = backend @trace = [] @env = nil @options = options initialize_options options yield self if block_given? @private_header_keys = private_headers.map { |name| "HTTP_#{name.upcase.tr('-', '_')}" } end
Public Instance Methods
Source
# File lib/rack/cache/context.rb, line 48 def call(env) if env['rack.run_once'] && !env['rack.multithread'] call! env else clone.call! env end 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.
Source
# File lib/rack/cache/context.rb, line 58 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 if @request.options? pass else invalidate end 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] log_info(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 real Rack call interface. The caching logic is performed within the context of the receiver.
Source
# File lib/rack/cache/context.rb, line 40 def entitystore uri = options['rack-cache.entitystore'] storage.resolve_entitystore_uri(uri, @options) end
The configured EntityStore instance. Changing the rack-cache.entitystore value effects the result of this method immediately.
Source
# File lib/rack/cache/context.rb, line 33 def metastore uri = options['rack-cache.metastore'] storage.resolve_metastore_uri(uri, @options) end
The configured MetaStore instance. Changing the rack-cache.metastore value effects the result of this method immediately.