Class: Rack::Cache::Context

Inherits:
Object
  • Object
show all
Includes:
Config, Core, Options
Defined in:
lib/rack/cache/context.rb

Overview

Implements Rack’s middleware interface and provides the context for all cache logic. This class includes the Options, Config, and Core modules to provide much of its core functionality.

Instance Attribute Summary collapse

Attributes included from Core

#entry, #original_request, #original_response, #request, #response

Instance Method Summary collapse

Methods included from Core

#on, #performed?

Methods included from Config

#configure, #import

Methods included from Options

#options, #options=, #set

Constructor Details

#initialize(backend, options = {}, &block) ⇒ Context

Returns a new instance of Context.



21
22
23
24
25
26
27
28
# File 'lib/rack/cache/context.rb', line 21

def initialize(backend, options={}, &block)
  @errors = nil
  @env = nil
  @backend = backend
  initialize_options options
  initialize_core
  initialize_config(&block)
end

Instance Attribute Details

#backendObject (readonly)

The Rack application object immediately downstream.



19
20
21
# File 'lib/rack/cache/context.rb', line 19

def backend
  @backend
end

Instance Method Details

#call(env) ⇒ Object

The Rack call interface. The receiver acts as a prototype and runs each request in a duplicate object, unless the rack.run_once variable is set in the environment.



38
39
40
41
42
43
44
# File 'lib/rack/cache/context.rb', line 38

def call(env)
  if env['rack.run_once']
    call! env
  else
    clone.call! env
  end
end

#entitystoreObject

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



68
69
70
71
# File 'lib/rack/cache/context.rb', line 68

def entitystore
  uri = options['rack-cache.entitystore']
  storage.resolve_entitystore_uri(uri)
end

#errorsObject

IO-like object that receives log, warning, and error messages; defaults to the rack.errors environment variable.



49
50
51
# File 'lib/rack/cache/context.rb', line 49

def errors
  @errors || (@env && (@errors = @env['rack.errors'])) || STDERR
end

#errors=(ioish) ⇒ Object

Set the output stream for log messages, warnings, and errors.



54
55
56
57
# File 'lib/rack/cache/context.rb', line 54

def errors=(ioish)
  fail "stream must respond to :write" if ! ioish.respond_to?(:write)
  @errors = ioish
end

#metastoreObject

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



61
62
63
64
# File 'lib/rack/cache/context.rb', line 61

def metastore
  uri = options['rack-cache.metastore']
  storage.resolve_metastore_uri(uri)
end