Class Rack::Cache::Context

  1. lib/rack/cache/context.rb
Parent: Object

Implements Rack’s middleware interface and provides the context for all cache logic, including the core logic engine.

Methods

public class

  1. new

public instance

  1. call
  2. call!
  3. entitystore
  4. metastore

Included modules

  1. Rack::Cache::Options

Attributes

backend [R] The Rack application object immediately downstream.
trace [R] Array of trace Symbols

Public class methods

new (backend, options={}) {|self if block_given?| ...}
[show source]
    # File lib/rack/cache/context.rb, line 18
18:     def initialize(backend, options={})
19:       @backend = backend
20:       @trace = []
21: 
22:       initialize_options options
23:       yield self if block_given?
24: 
25:       @private_header_keys =
26:         private_headers.map { |name| "HTTP_#{name.upcase.tr('-', '_')}" }
27:     end

Public instance methods

call (env)

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.

[show source]
    # File lib/rack/cache/context.rb, line 46
46:     def call(env)
47:       if env['rack.run_once']
48:         call! env
49:       else
50:         clone.call! env
51:       end
52:     end
call! (env)

The real Rack call interface. The caching logic is performed within the context of the receiver.

[show source]
    # File lib/rack/cache/context.rb, line 56
56:     def call!(env)
57:       @trace = []
58:       @default_options.each { |k,v| env[k] ||= v }
59:       @env = env
60:       @request = Request.new(@env.dup.freeze)
61: 
62:       response =
63:         if @request.get? || @request.head?
64:           if !@env['HTTP_EXPECT']
65:             lookup
66:           else
67:             pass
68:           end
69:         else
70:           invalidate
71:         end
72: 
73:       # log trace and set X-Rack-Cache tracing header
74:       trace = @trace.join(', ')
75:       response.headers['X-Rack-Cache'] = trace
76: 
77:       # write log message to rack.errors
78:       if verbose?
79:         message = "cache: [%s %s] %s\n" %
80:           [@request.request_method, @request.fullpath, trace]
81:         @env['rack.errors'].write(message)
82:       end
83: 
84:       # tidy up response a bit
85:       response.not_modified! if not_modified?(response)
86:       response.body = [] if @request.head?
87:       response.to_a
88:     end
entitystore ()

The configured EntityStore instance. Changing the rack-cache.entitystore value effects the result of this method immediately.

[show source]
    # File lib/rack/cache/context.rb, line 38
38:     def entitystore
39:       uri = options['rack-cache.entitystore']
40:       storage.resolve_entitystore_uri(uri)
41:     end
metastore ()

The configured MetaStore instance. Changing the rack-cache.metastore value effects the result of this method immediately.

[show source]
    # File lib/rack/cache/context.rb, line 31
31:     def metastore
32:       uri = options['rack-cache.metastore']
33:       storage.resolve_metastore_uri(uri)
34:     end