Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 373
- Log:
Initial import of Radiant 0.9.1, which is now packaged as a gem. This is an
import of the tagged 0.9.1 source checked out from GitHub, which isn't quite
the same as the gem distribution - but it doesn't seem to be available in an
archived form and the installed gem already has modifications, so this is
the closest I can get.
- Author:
- rool
- Date:
- Mon Mar 21 13:40:05 +0000 2011
- Size:
- 5564 Bytes
1 | require 'rack/cache/key' |
2 | require 'rack/cache/storage' |
3 | |
4 | module Rack::Cache |
5 | |
6 | # Configuration options and utility methods for option access. Rack::Cache |
7 | # uses the Rack Environment to store option values. All options documented |
8 | # below are stored in the Rack Environment as "rack-cache.<option>", where |
9 | # <option> is the option name. |
10 | module Options |
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 |
17 | |
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 |
25 | module_function :option_name |
26 | |
27 | # Enable verbose trace logging. This option is currently enabled by |
28 | # default but is likely to be disabled in a future release. |
29 | option_accessor :verbose |
30 | |
31 | # The storage resolver. Defaults to the Rack::Cache.storage singleton instance |
32 | # of Rack::Cache::Storage. This object is responsible for resolving metastore |
33 | # and entitystore URIs to an implementation instances. |
34 | option_accessor :storage |
35 | |
36 | # A URI specifying the meta-store implementation that should be used to store |
37 | # request/response meta information. The following URIs schemes are |
38 | # supported: |
39 | # |
40 | # * heap:/ |
41 | # * file:/absolute/path or file:relative/path |
42 | # * memcached://localhost:11211[/namespace] |
43 | # |
44 | # If no meta store is specified the 'heap:/' store is assumed. This |
45 | # implementation has significant draw-backs so explicit configuration is |
46 | # recommended. |
47 | option_accessor :metastore |
48 | |
49 | # A custom cache key generator, which can be anything that responds to :call. |
50 | # By default, this is the Rack::Cache::Key class, but you can implement your |
51 | # own generator. A cache key generator gets passed a request and generates the |
52 | # appropriate cache key. |
53 | # |
54 | # In addition to setting the generator to an object, you can just pass a block |
55 | # instead, which will act as the cache key generator: |
56 | # |
57 | # set :cache_key do |request| |
58 | # request.fullpath.replace(/\//, '-') |
59 | # end |
60 | option_accessor :cache_key |
61 | |
62 | # A URI specifying the entity-store implementation that should be used to |
63 | # store response bodies. See the metastore option for information on |
64 | # supported URI schemes. |
65 | # |
66 | # If no entity store is specified the 'heap:/' store is assumed. This |
67 | # implementation has significant draw-backs so explicit configuration is |
68 | # recommended. |
69 | option_accessor :entitystore |
70 | |
71 | # The number of seconds that a cache entry should be considered |
72 | # "fresh" when no explicit freshness information is provided in |
73 | # a response. Explicit Cache-Control or Expires headers |
74 | # override this value. |
75 | # |
76 | # Default: 0 |
77 | option_accessor :default_ttl |
78 | |
79 | # Set of request headers that trigger "private" cache-control behavior |
80 | # on responses that don't explicitly state whether the response is |
81 | # public or private via a Cache-Control directive. Applications that use |
82 | # cookies for authorization may need to add the 'Cookie' header to this |
83 | # list. |
84 | # |
85 | # Default: ['Authorization', 'Cookie'] |
86 | option_accessor :private_headers |
87 | |
88 | # Specifies whether the client can force a cache reload by including a |
89 | # Cache-Control "no-cache" directive in the request. This is enabled by |
90 | # default for compliance with RFC 2616. |
91 | option_accessor :allow_reload |
92 | |
93 | # Specifies whether the client can force a cache revalidate by including |
94 | # a Cache-Control "max-age=0" directive in the request. This is enabled by |
95 | # default for compliance with RFC 2616. |
96 | option_accessor :allow_revalidate |
97 | |
98 | # The underlying options Hash. During initialization (or outside of a |
99 | # request), this is a default values Hash. During a request, this is the |
100 | # Rack environment Hash. The default values Hash is merged in underneath |
101 | # the Rack environment before each request is processed. |
102 | def options |
103 | @env || @default_options |
104 | end |
105 | |
106 | # Set multiple options. |
107 | def options=(hash={}) |
108 | hash.each { |key,value| write_option(key, value) } |
109 | end |
110 | |
111 | # Set an option. When +option+ is a Symbol, it is set in the Rack |
112 | # Environment as "rack-cache.option". When +option+ is a String, it |
113 | # exactly as specified. The +option+ argument may also be a Hash in |
114 | # which case each key/value pair is merged into the environment as if |
115 | # the #set method were called on each. |
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 |
125 | |
126 | private |
127 | def initialize_options(options={}) |
128 | @default_options = { |
129 | 'rack-cache.cache_key' => Key, |
130 | 'rack-cache.verbose' => true, |
131 | 'rack-cache.storage' => Rack::Cache::Storage.instance, |
132 | 'rack-cache.metastore' => 'heap:/', |
133 | 'rack-cache.entitystore' => 'heap:/', |
134 | 'rack-cache.default_ttl' => 0, |
135 | 'rack-cache.private_headers' => ['Authorization', 'Cookie'], |
136 | 'rack-cache.allow_reload' => true, |
137 | 'rack-cache.allow_revalidate' => true |
138 | } |
139 | self.options = options |
140 | end |
141 | |
142 | def read_option(key) |
143 | options[option_name(key)] |
144 | end |
145 | |
146 | def write_option(key, value) |
147 | options[option_name(key)] = value |
148 | end |
149 | end |
150 | end |