Module Rack::Cache::Options

  1. lib/rack/cache/options.rb

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.

Methods

public class

  1. option_accessor
  2. option_name

public instance

  1. options
  2. options=
  3. set

Attributes

allow_reload [RW] Specifies whether the client can force a cache reload by including a Cache-Control “no-cache” directive in the request. This is enabled by default for compliance with RFC 2616.
allow_revalidate [RW] Specifies whether the client can force a cache revalidate by including a Cache-Control “max-age=0” directive in the request. This is enabled by default for compliance with RFC 2616.
cache_key [RW] A custom cache key generator, which can be anything that responds to :call. By default, this is the Rack::Cache::Key class, but you can implement your own generator. A cache key generator gets passed a request and generates the appropriate cache key.

In addition to setting the generator to an object, you can just pass a block instead, which will act as the cache key generator:

set :cache_key do |request|
  request.fullpath.replace(/\//, '-')
end
default_ttl [RW] The number of seconds that a cache entry should be considered “fresh” when no explicit freshness information is provided in a response. Explicit Cache-Control or Expires headers override this value.

Default: 0

entitystore [RW] A URI specifying the entity-store implementation that should be used to store response bodies. See the metastore option for information on supported URI schemes.

If no entity store is specified the ‘heap:/’ store is assumed. This implementation has significant draw-backs so explicit configuration is recommended.

metastore [RW] A URI specifying the meta-store implementation that should be used to store request/response meta information. The following URIs schemes are supported:
  • heap:/
  • file:/absolute/path or file:relative/path
  • memcached://localhost:11211[/namespace]

If no meta store is specified the ‘heap:/’ store is assumed. This implementation has significant draw-backs so explicit configuration is recommended.

private_headers [RW] Set of request headers that trigger “private” cache-control behavior on responses that don’t explicitly state whether the response is public or private via a Cache-Control directive. Applications that use cookies for authorization may need to add the ‘Cookie’ header to this list.

Default: [‘Authorization’, ‘Cookie’]

storage [RW] The storage resolver. Defaults to the Rack::Cache.storage singleton instance of Rack::Cache::Storage. This object is responsible for resolving metastore and entitystore URIs to an implementation instances.
verbose [RW] Enable verbose trace logging. This option is currently enabled by default but is likely to be disabled in a future release.

Public class methods

option_accessor (key)
[show source]
    # File lib/rack/cache/options.rb, line 11
11:     def self.option_accessor(key)
12:       name = option_name(key)
13:       define_method(key) { || options[name] }
14:       define_method("#{key}=") { |value| options[name] = value }
15:       define_method("#{key}?") { || !! options[name] }
16:     end
option_name (key)
[show source]
    # File lib/rack/cache/options.rb, line 18
18:     def option_name(key)
19:       case key
20:       when Symbol ; "rack-cache.#{key}"
21:       when String ; key
22:       else raise ArgumentError
23:       end
24:     end

Public instance methods

options ()

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.

[show source]
     # File lib/rack/cache/options.rb, line 102
102:     def options
103:       @env || @default_options
104:     end
options= (hash={})

Set multiple options.

[show source]
     # File lib/rack/cache/options.rb, line 107
107:     def options=(hash={})
108:       hash.each { |key,value| write_option(key, value) }
109:     end
set (option, value=self, &block)

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.

[show source]
     # File lib/rack/cache/options.rb, line 116
116:     def set(option, value=self, &block)
117:       if block_given?
118:         write_option option, block
119:       elsif value == self
120:         self.options = option.to_hash
121:       else
122:         write_option option, value
123:       end
124:     end