Class: Rack::Cache::Context
- Inherits:
-
Object
- Object
- Rack::Cache::Context
- 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
-
#backend ⇒ Object
readonly
The Rack application object immediately downstream.
Attributes included from Core
#entry, #original_request, #original_response, #request, #response
Instance Method Summary collapse
-
#call(env) ⇒ Object
The Rack call interface.
-
#entitystore ⇒ Object
The configured EntityStore instance.
-
#errors ⇒ Object
IO-like object that receives log, warning, and error messages; defaults to the rack.errors environment variable.
-
#errors=(ioish) ⇒ Object
Set the output stream for log messages, warnings, and errors.
-
#initialize(backend, options = {}, &block) ⇒ Context
constructor
A new instance of Context.
-
#metastore ⇒ Object
The configured MetaStore instance.
Methods included from Core
Methods included from Config
Methods included from Options
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, ={}, &block) @errors = nil @env = nil @backend = backend initialize_core initialize_config(&block) end |
Instance Attribute Details
#backend ⇒ Object (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 |
#entitystore ⇒ Object
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 = ['rack-cache.entitystore'] storage.resolve_entitystore_uri(uri) end |
#errors ⇒ Object
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 |
#metastore ⇒ Object
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 uri = ['rack-cache.metastore'] storage.(uri) end |