module Rack::Cache::Options

Configuration options and utility methods for option access. Rack::Cache uses the Rack Environment to store option values. All options documented below are stored in the Rack Environment as “rack-cache.<option>”, where <option> is the option name.

Public Class Methods

option_accessor(key) click to toggle source
   # File lib/rack/cache/options.rb
13 def self.option_accessor(key)
14   name = option_name(key)
15   define_method(key) { || options[name] }
16   define_method("#{key}=") { |value| options[name] = value }
17   define_method("#{key}?") { || !! options[name] }
18 end
option_name(key) click to toggle source
   # File lib/rack/cache/options.rb
20 def option_name(key)
21   case key
22   when Symbol ; "rack-cache.#{key}"
23   when String ; key
24   else raise ArgumentError
25   end
26 end

Public Instance Methods

options() click to toggle source

The underlying options Hash. During initialization (or outside of a request), this is a default values Hash. During a request, this is the Rack environment Hash. The default values Hash is merged in underneath the Rack environment before each request is processed.

    # File lib/rack/cache/options.rb
118 def options
119   @env || @default_options
120 end
options=(hash={}) click to toggle source

Set multiple options.

    # File lib/rack/cache/options.rb
123 def options=(hash={})
124   hash.each { |key,value| write_option(key, value) }
125 end
set(option, value=self, &block) click to toggle source

Set an option. When option is a Symbol, it is set in the Rack Environment as “rack-cache.option”. When option is a String, it exactly as specified. The option argument may also be a Hash in which case each key/value pair is merged into the environment as if the set method were called on each.

    # File lib/rack/cache/options.rb
132 def set(option, value=self, &block)
133   if block_given?
134     write_option option, block
135   elsif value == self
136     self.options = option.to_hash
137   else
138     write_option option, value
139   end
140 end

Private Instance Methods

initialize_options(options={}) click to toggle source
    # File lib/rack/cache/options.rb
143 def initialize_options(options={})
144   @default_options = {
145     'rack-cache.cache_key'        => Key,
146     'rack-cache.verbose'          => true,
147     'rack-cache.storage'          => Rack::Cache::Storage.instance,
148     'rack-cache.metastore'        => 'heap:/',
149     'rack-cache.entitystore'      => 'heap:/',
150     'rack-cache.default_ttl'      => 0,
151     'rack-cache.ignore_headers'   => ['Set-Cookie'],
152     'rack-cache.private_headers'  => ['Authorization', 'Cookie'],
153     'rack-cache.allow_reload'     => false,
154     'rack-cache.allow_revalidate' => false,
155     'rack-cache.use_native_ttl'   => false,
156     'rack-cache.fault_tolerant'   => false,
157   }
158   self.options = options
159 end
option_name(key) click to toggle source
   # File lib/rack/cache/options.rb
20 def option_name(key)
21   case key
22   when Symbol ; "rack-cache.#{key}"
23   when String ; key
24   else raise ArgumentError
25   end
26 end
read_option(key) click to toggle source
    # File lib/rack/cache/options.rb
161 def read_option(key)
162   options[option_name(key)]
163 end
write_option(key, value) click to toggle source
    # File lib/rack/cache/options.rb
165 def write_option(key, value)
166   options[option_name(key)] = value
167 end