rack-cache 1.2 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/{COPYING → MIT-LICENSE} +0 -0
- data/README.md +95 -0
- data/lib/rack/cache/cachecontrol.rb +14 -0
- data/lib/rack/cache/context.rb +16 -3
- data/lib/rack/cache/metastore.rb +1 -1
- data/lib/rack/cache/options.rb +4 -6
- data/lib/rack/cache/response.rb +13 -6
- metadata +76 -74
- data/Gemfile +0 -2
- data/README +0 -126
- data/Rakefile +0 -139
- data/TODO +0 -27
- data/doc/configuration.markdown +0 -127
- data/doc/faq.markdown +0 -148
- data/doc/index.markdown +0 -121
- data/doc/layout.html.erb +0 -34
- data/doc/license.markdown +0 -24
- data/doc/rack-cache.css +0 -362
- data/doc/server.ru +0 -34
- data/doc/storage.markdown +0 -164
- data/example/sinatra/app.rb +0 -21
- data/example/sinatra/views/index.erb +0 -44
- data/rack-cache.gemspec +0 -75
- data/test/cache_test.rb +0 -38
- data/test/cachecontrol_test.rb +0 -145
- data/test/context_test.rb +0 -916
- data/test/entitystore_test.rb +0 -268
- data/test/key_test.rb +0 -50
- data/test/metastore_test.rb +0 -338
- data/test/options_test.rb +0 -77
- data/test/pony.jpg +0 -0
- data/test/request_test.rb +0 -19
- data/test/response_test.rb +0 -184
- data/test/spec_setup.rb +0 -232
- data/test/storage_test.rb +0 -94
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d540010c6bce635d24b70fe8a0484d901d76fd1d
|
4
|
+
data.tar.gz: 5e114ab9a12b2465ddcd2852b5e68a7901e1774e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d85a27db86e5ce6980ff0e7287041f17a21f58a7be044f8614caab4470340f566a483fdb6ad9152d75452e0a705af654b755c7c139d31b1c6a5e3f046e1d9692
|
7
|
+
data.tar.gz: b481ec44add4cd159aa65750c1477dd4d8190b84154d9eacae03b10e529af9a8791a1cc15741ae78e45787082c82dd4160721e37263bdd0ddc0cda426f88ff46
|
data/{COPYING → MIT-LICENSE}
RENAMED
File without changes
|
data/README.md
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
Rack::Cache
|
2
|
+
===========
|
3
|
+
|
4
|
+
Rack::Cache is suitable as a quick drop-in component to enable HTTP caching for
|
5
|
+
Rack-based applications that produce freshness (Expires, Cache-Control) and/or
|
6
|
+
validation (Last-Modified, ETag) information:
|
7
|
+
|
8
|
+
* Standards-based (RFC 2616)
|
9
|
+
* Freshness/expiration based caching
|
10
|
+
* Validation (If-Modified-Since / If-None-Match)
|
11
|
+
* Vary support
|
12
|
+
* Cache-Control: public, private, max-age, s-maxage, must-revalidate,
|
13
|
+
and proxy-revalidate.
|
14
|
+
* Portable: 100% Ruby / works with any Rack-enabled framework
|
15
|
+
* Disk, memcached, and heap memory storage backends
|
16
|
+
|
17
|
+
For more information about Rack::Cache features and usage, see:
|
18
|
+
|
19
|
+
http://rtomayko.github.com/rack-cache/
|
20
|
+
|
21
|
+
Rack::Cache is not overly optimized for performance. The main goal of the
|
22
|
+
project is to provide a portable, easy-to-configure, and standards-based
|
23
|
+
caching solution for small to medium sized deployments. More sophisticated /
|
24
|
+
high-performance caching systems (e.g., Varnish, Squid, httpd/mod-cache) may be
|
25
|
+
more appropriate for large deployments with significant throughput requirements.
|
26
|
+
|
27
|
+
Installation
|
28
|
+
------------
|
29
|
+
|
30
|
+
gem install rack-cache
|
31
|
+
|
32
|
+
Basic Usage
|
33
|
+
-----------
|
34
|
+
|
35
|
+
`Rack::Cache` is implemented as a piece of Rack middleware and can be used with
|
36
|
+
any Rack-based application. If your application includes a rackup (`.ru`) file
|
37
|
+
or uses Rack::Builder to construct the application pipeline, simply require
|
38
|
+
and use as follows:
|
39
|
+
|
40
|
+
```Ruby
|
41
|
+
require 'rack/cache'
|
42
|
+
|
43
|
+
use Rack::Cache,
|
44
|
+
:metastore => 'file:/var/cache/rack/meta',
|
45
|
+
:entitystore => 'file:/var/cache/rack/body',
|
46
|
+
:verbose => true
|
47
|
+
|
48
|
+
run app
|
49
|
+
```
|
50
|
+
|
51
|
+
Assuming you've designed your backend application to take advantage of HTTP's
|
52
|
+
caching features, no further code or configuration is required for basic
|
53
|
+
caching.
|
54
|
+
|
55
|
+
Using with Rails
|
56
|
+
----------------
|
57
|
+
|
58
|
+
Add this to your `config/environment.rb`:
|
59
|
+
|
60
|
+
```Ruby
|
61
|
+
config.middleware.use Rack::Cache,
|
62
|
+
:verbose => true,
|
63
|
+
:metastore => 'file:/var/cache/rack/meta',
|
64
|
+
:entitystore => 'file:/var/cache/rack/body'
|
65
|
+
```
|
66
|
+
|
67
|
+
You should now see `Rack::Cache` listed in the middleware pipeline:
|
68
|
+
|
69
|
+
rake middleware
|
70
|
+
|
71
|
+
See the following for more information:
|
72
|
+
|
73
|
+
http://snippets.aktagon.com/snippets/302
|
74
|
+
|
75
|
+
Using with Dalli
|
76
|
+
----------------
|
77
|
+
|
78
|
+
Dalli is a high performance memcached client for Ruby.
|
79
|
+
More information at: https://github.com/mperham/dalli
|
80
|
+
|
81
|
+
```Ruby
|
82
|
+
require 'dalli'
|
83
|
+
require 'rack/cache'
|
84
|
+
|
85
|
+
use Rack::Cache,
|
86
|
+
:verbose => true,
|
87
|
+
:metastore => "memcached://localhost:11211/meta",
|
88
|
+
:entitystore => "memcached://localhost:11211/body"
|
89
|
+
|
90
|
+
run app
|
91
|
+
```
|
92
|
+
|
93
|
+
License: MIT<br/>
|
94
|
+
[](https://travis-ci.org/rtomayko/rack-cache)
|
95
|
+
|
@@ -125,6 +125,20 @@ module Rack
|
|
125
125
|
end
|
126
126
|
alias_method :s_maxage, :shared_max_age
|
127
127
|
|
128
|
+
# If a response includes a r-maxage directive, then for a reverse cache
|
129
|
+
# (but not for a private or proxy cache), the maximum age specified by
|
130
|
+
# this directive overrides the maximum age specified by either the max-age
|
131
|
+
# directive, the s-maxage directive, or the Expires header. The r-maxage
|
132
|
+
# directive also implies the semantics of the proxy-revalidate directive.
|
133
|
+
# i.e., that the reverse cache must not use the entry after it becomes
|
134
|
+
# stale to respond to a subsequent request without first revalidating it
|
135
|
+
# with the origin server. The r-maxage directive is always ignored by
|
136
|
+
# private and proxy caches.
|
137
|
+
def reverse_max_age
|
138
|
+
self['r-maxage'].to_i if key?('r-maxage')
|
139
|
+
end
|
140
|
+
alias_method :r_maxage, :reverse_max_age
|
141
|
+
|
128
142
|
# Because a cache MAY be configured to ignore a server's specified
|
129
143
|
# expiration time, and because a client request MAY include a max-
|
130
144
|
# stale directive (which has a similar effect), the protocol also
|
data/lib/rack/cache/context.rb
CHANGED
@@ -45,7 +45,7 @@ module Rack::Cache
|
|
45
45
|
# each request in a dup object unless the +rack.run_once+ variable is
|
46
46
|
# set in the environment.
|
47
47
|
def call(env)
|
48
|
-
if env['rack.run_once']
|
48
|
+
if env['rack.run_once'] && !env['rack.multithread']
|
49
49
|
call! env
|
50
50
|
else
|
51
51
|
clone.call! env
|
@@ -79,7 +79,7 @@ module Rack::Cache
|
|
79
79
|
if verbose?
|
80
80
|
message = "cache: [%s %s] %s\n" %
|
81
81
|
[@request.request_method, @request.fullpath, trace]
|
82
|
-
|
82
|
+
log_info(message)
|
83
83
|
end
|
84
84
|
|
85
85
|
# tidy up response a bit
|
@@ -280,7 +280,20 @@ module Rack::Cache
|
|
280
280
|
end
|
281
281
|
|
282
282
|
def log_error(exception)
|
283
|
-
|
283
|
+
message = "cache error: #{exception.message}\n#{exception.backtrace.join("\n")}\n"
|
284
|
+
log(:error, message)
|
285
|
+
end
|
286
|
+
|
287
|
+
def log_info(message)
|
288
|
+
log(:info, message)
|
289
|
+
end
|
290
|
+
|
291
|
+
def log(level, message)
|
292
|
+
if @env['rack.logger']
|
293
|
+
@env['rack.logger'].send(level, message)
|
294
|
+
else
|
295
|
+
@env['rack.errors'].write(message)
|
296
|
+
end
|
284
297
|
end
|
285
298
|
end
|
286
299
|
end
|
data/lib/rack/cache/metastore.rb
CHANGED
@@ -64,7 +64,7 @@ module Rack::Cache
|
|
64
64
|
end
|
65
65
|
response.headers['X-Content-Digest'] = digest
|
66
66
|
response.headers['Content-Length'] = size.to_s unless response.headers['Transfer-Encoding']
|
67
|
-
response.body = entity_store.open(digest)
|
67
|
+
response.body = entity_store.open(digest) || response.body
|
68
68
|
end
|
69
69
|
|
70
70
|
# read existing cache entries, remove non-varying, and add this one to
|
data/lib/rack/cache/options.rb
CHANGED
@@ -95,14 +95,12 @@ module Rack::Cache
|
|
95
95
|
# Default: ['Authorization', 'Cookie']
|
96
96
|
option_accessor :private_headers
|
97
97
|
|
98
|
-
# Specifies whether
|
99
|
-
# Cache-Control "no-cache" directive in the request.
|
100
|
-
# default for compliance with RFC 2616.
|
98
|
+
# Specifies whether a client can force cache reload by including a
|
99
|
+
# Cache-Control "no-cache" directive in the request. Disabled by default.
|
101
100
|
option_accessor :allow_reload
|
102
101
|
|
103
|
-
# Specifies whether
|
104
|
-
#
|
105
|
-
# default for compliance with RFC 2616.
|
102
|
+
# Specifies whether a client can force cache revalidate by including a
|
103
|
+
# Cache-Control "max-age=0" directive in the request. Disabled by default.
|
106
104
|
option_accessor :allow_revalidate
|
107
105
|
|
108
106
|
# Specifies whether the underlying entity store's native expiration should
|
data/lib/rack/cache/response.rb
CHANGED
@@ -151,13 +151,14 @@ module Rack::Cache
|
|
151
151
|
|
152
152
|
# The number of seconds after the time specified in the response's Date
|
153
153
|
# header when the the response should no longer be considered fresh. First
|
154
|
-
# check for a
|
155
|
-
# back on an expires header; return nil when no
|
156
|
-
# established.
|
154
|
+
# check for a r-maxage directive, then a s-maxage directive, then a max-age
|
155
|
+
# directive, and then fall back on an expires header; return nil when no
|
156
|
+
# maximum age can be established.
|
157
157
|
def max_age
|
158
|
-
cache_control.
|
159
|
-
cache_control.
|
160
|
-
|
158
|
+
cache_control.reverse_max_age ||
|
159
|
+
cache_control.shared_max_age ||
|
160
|
+
cache_control.max_age ||
|
161
|
+
(expires && (expires - date))
|
161
162
|
end
|
162
163
|
|
163
164
|
# The value of the Expires header as a Time object.
|
@@ -177,6 +178,12 @@ module Rack::Cache
|
|
177
178
|
self.cache_control = cache_control.merge('s-maxage' => value.to_s)
|
178
179
|
end
|
179
180
|
|
181
|
+
# Like #shared_max_age= but sets the r-maxage directive, which applies only
|
182
|
+
# to reverse caches.
|
183
|
+
def reverse_max_age=(value)
|
184
|
+
self.cache_control = cache_control.merge('r-maxage' => value.to_s)
|
185
|
+
end
|
186
|
+
|
180
187
|
# The response's time-to-live in seconds, or nil when no freshness
|
181
188
|
# information is present in the response. When the responses #ttl
|
182
189
|
# is <= 0, the response may not be served from cache without first
|
metadata
CHANGED
@@ -1,60 +1,99 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
5
|
-
prerelease:
|
4
|
+
version: 1.3.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Ryan Tomayko
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-10-06 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rack
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0.4'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.4'
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
28
|
name: bacon
|
27
|
-
requirement:
|
28
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
|
-
- -
|
31
|
+
- - ">="
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: '0'
|
33
34
|
type: :development
|
34
35
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
36
41
|
- !ruby/object:Gem::Dependency
|
37
42
|
name: memcached
|
38
|
-
requirement:
|
39
|
-
none: false
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
40
44
|
requirements:
|
41
|
-
- -
|
45
|
+
- - ">="
|
42
46
|
- !ruby/object:Gem::Version
|
43
47
|
version: '0'
|
44
48
|
type: :development
|
45
49
|
prerelease: false
|
46
|
-
version_requirements:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
47
55
|
- !ruby/object:Gem::Dependency
|
48
56
|
name: dalli
|
49
|
-
requirement:
|
50
|
-
none: false
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
51
58
|
requirements:
|
52
|
-
- -
|
59
|
+
- - ">="
|
53
60
|
- !ruby/object:Gem::Version
|
54
61
|
version: '0'
|
55
62
|
type: :development
|
56
63
|
prerelease: false
|
57
|
-
version_requirements:
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bump
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
58
97
|
description: Rack::Cache is suitable as a quick drop-in component to enable HTTP caching
|
59
98
|
for Rack-based applications that produce freshness (Expires, Cache-Control) and/or
|
60
99
|
validation (Last-Modified, ETag) information.
|
@@ -62,27 +101,13 @@ email: r@tomayko.com
|
|
62
101
|
executables: []
|
63
102
|
extensions: []
|
64
103
|
extra_rdoc_files:
|
65
|
-
- README
|
66
|
-
-
|
67
|
-
- TODO
|
104
|
+
- README.md
|
105
|
+
- MIT-LICENSE
|
68
106
|
- CHANGES
|
69
107
|
files:
|
70
108
|
- CHANGES
|
71
|
-
-
|
72
|
-
-
|
73
|
-
- README
|
74
|
-
- Rakefile
|
75
|
-
- TODO
|
76
|
-
- doc/configuration.markdown
|
77
|
-
- doc/faq.markdown
|
78
|
-
- doc/index.markdown
|
79
|
-
- doc/layout.html.erb
|
80
|
-
- doc/license.markdown
|
81
|
-
- doc/rack-cache.css
|
82
|
-
- doc/server.ru
|
83
|
-
- doc/storage.markdown
|
84
|
-
- example/sinatra/app.rb
|
85
|
-
- example/sinatra/views/index.erb
|
109
|
+
- MIT-LICENSE
|
110
|
+
- README.md
|
86
111
|
- lib/rack-cache.rb
|
87
112
|
- lib/rack/cache.rb
|
88
113
|
- lib/rack/cache/appengine.rb
|
@@ -95,57 +120,34 @@ files:
|
|
95
120
|
- lib/rack/cache/request.rb
|
96
121
|
- lib/rack/cache/response.rb
|
97
122
|
- lib/rack/cache/storage.rb
|
98
|
-
|
99
|
-
|
100
|
-
-
|
101
|
-
|
102
|
-
- test/entitystore_test.rb
|
103
|
-
- test/key_test.rb
|
104
|
-
- test/metastore_test.rb
|
105
|
-
- test/options_test.rb
|
106
|
-
- test/pony.jpg
|
107
|
-
- test/request_test.rb
|
108
|
-
- test/response_test.rb
|
109
|
-
- test/spec_setup.rb
|
110
|
-
- test/storage_test.rb
|
111
|
-
homepage: http://tomayko.com/src/rack-cache/
|
112
|
-
licenses: []
|
123
|
+
homepage: https://github.com/rtomayko/rack-cache
|
124
|
+
licenses:
|
125
|
+
- MIT
|
126
|
+
metadata: {}
|
113
127
|
post_install_message:
|
114
128
|
rdoc_options:
|
115
|
-
- --line-numbers
|
116
|
-
- --inline-source
|
117
|
-
- --title
|
129
|
+
- "--line-numbers"
|
130
|
+
- "--inline-source"
|
131
|
+
- "--title"
|
118
132
|
- Rack::Cache
|
119
|
-
- --main
|
133
|
+
- "--main"
|
120
134
|
- Rack::Cache
|
121
135
|
require_paths:
|
122
136
|
- lib
|
123
137
|
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
-
none: false
|
125
138
|
requirements:
|
126
|
-
- -
|
139
|
+
- - ">="
|
127
140
|
- !ruby/object:Gem::Version
|
128
|
-
version:
|
141
|
+
version: 2.0.0
|
129
142
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
-
none: false
|
131
143
|
requirements:
|
132
|
-
- -
|
144
|
+
- - ">="
|
133
145
|
- !ruby/object:Gem::Version
|
134
146
|
version: '0'
|
135
147
|
requirements: []
|
136
148
|
rubyforge_project:
|
137
|
-
rubygems_version:
|
149
|
+
rubygems_version: 2.4.5.1
|
138
150
|
signing_key:
|
139
|
-
specification_version:
|
151
|
+
specification_version: 4
|
140
152
|
summary: HTTP Caching for Rack
|
141
|
-
test_files:
|
142
|
-
- test/cache_test.rb
|
143
|
-
- test/cachecontrol_test.rb
|
144
|
-
- test/context_test.rb
|
145
|
-
- test/entitystore_test.rb
|
146
|
-
- test/key_test.rb
|
147
|
-
- test/metastore_test.rb
|
148
|
-
- test/options_test.rb
|
149
|
-
- test/request_test.rb
|
150
|
-
- test/response_test.rb
|
151
|
-
- test/storage_test.rb
|
153
|
+
test_files: []
|
data/Gemfile
DELETED
data/README
DELETED
@@ -1,126 +0,0 @@
|
|
1
|
-
Rack::Cache
|
2
|
-
===========
|
3
|
-
|
4
|
-
Rack::Cache is suitable as a quick drop-in component to enable HTTP caching for
|
5
|
-
Rack-based applications that produce freshness (Expires, Cache-Control) and/or
|
6
|
-
validation (Last-Modified, ETag) information:
|
7
|
-
|
8
|
-
* Standards-based (RFC 2616)
|
9
|
-
* Freshness/expiration based caching
|
10
|
-
* Validation (If-Modified-Since / If-None-Match)
|
11
|
-
* Vary support
|
12
|
-
* Cache-Control: public, private, max-age, s-maxage, must-revalidate,
|
13
|
-
and proxy-revalidate.
|
14
|
-
* Portable: 100% Ruby / works with any Rack-enabled framework
|
15
|
-
* Disk, memcached, and heap memory storage backends
|
16
|
-
|
17
|
-
For more information about Rack::Cache features and usage, see:
|
18
|
-
|
19
|
-
http://tomayko.com/src/rack-cache/
|
20
|
-
|
21
|
-
Rack::Cache is not overly optimized for performance. The main goal of the
|
22
|
-
project is to provide a portable, easy-to-configure, and standards-based
|
23
|
-
caching solution for small to medium sized deployments. More sophisticated /
|
24
|
-
high-performance caching systems (e.g., Varnish, Squid, httpd/mod-cache) may be
|
25
|
-
more appropriate for large deployments with significant throughput requirements.
|
26
|
-
|
27
|
-
Installation
|
28
|
-
------------
|
29
|
-
|
30
|
-
From Gem:
|
31
|
-
|
32
|
-
$ sudo gem install rack-cache
|
33
|
-
|
34
|
-
With a local working copy:
|
35
|
-
|
36
|
-
$ git clone git://github.com/rtomayko/rack-cache.git
|
37
|
-
$ rake package && sudo rake install
|
38
|
-
|
39
|
-
Basic Usage
|
40
|
-
-----------
|
41
|
-
|
42
|
-
Rack::Cache is implemented as a piece of Rack middleware and can be used with
|
43
|
-
any Rack-based application. If your application includes a rackup (`.ru`) file
|
44
|
-
or uses Rack::Builder to construct the application pipeline, simply require
|
45
|
-
and use as follows:
|
46
|
-
|
47
|
-
require 'rack/cache'
|
48
|
-
|
49
|
-
use Rack::Cache,
|
50
|
-
:metastore => 'file:/var/cache/rack/meta',
|
51
|
-
:entitystore => 'file:/var/cache/rack/body',
|
52
|
-
:verbose => true
|
53
|
-
|
54
|
-
run app
|
55
|
-
|
56
|
-
Assuming you've designed your backend application to take advantage of HTTP's
|
57
|
-
caching features, no further code or configuration is required for basic
|
58
|
-
caching.
|
59
|
-
|
60
|
-
Using with Rails
|
61
|
-
----------------
|
62
|
-
|
63
|
-
Add this to your `config/environment.rb`:
|
64
|
-
|
65
|
-
config.middleware.use Rack::Cache,
|
66
|
-
:verbose => true,
|
67
|
-
:metastore => 'file:/var/cache/rack/meta',
|
68
|
-
:entitystore => 'file:/var/cache/rack/body'
|
69
|
-
|
70
|
-
You should now see `Rack::Cache` listed in the middleware pipeline:
|
71
|
-
|
72
|
-
rake middleware
|
73
|
-
|
74
|
-
See the following for more information:
|
75
|
-
|
76
|
-
http://snippets.aktagon.com/snippets/302
|
77
|
-
|
78
|
-
Using with Dalli
|
79
|
-
----------------
|
80
|
-
|
81
|
-
Dalli is a high performance memcached client for Ruby.
|
82
|
-
More information at: https://github.com/mperham/dalli
|
83
|
-
|
84
|
-
require 'dalli'
|
85
|
-
require 'rack/cache'
|
86
|
-
|
87
|
-
use Rack::Cache,
|
88
|
-
:verbose => true,
|
89
|
-
:metastore => "memcached://localhost:11211/meta",
|
90
|
-
:entitystore => "memcached://localhost:11211/body"
|
91
|
-
|
92
|
-
run app
|
93
|
-
|
94
|
-
Links
|
95
|
-
-----
|
96
|
-
|
97
|
-
Documentation:
|
98
|
-
http://tomayko.com/src/rack-cache/
|
99
|
-
|
100
|
-
Mailing List:
|
101
|
-
http://groups.google.com/group/rack-cache
|
102
|
-
|
103
|
-
GitHub:
|
104
|
-
http://github.com/rtomayko/rack-cache/
|
105
|
-
|
106
|
-
License
|
107
|
-
-------
|
108
|
-
|
109
|
-
Copyright (c) 2008 Ryan Tomayko <http://tomayko.com/about>
|
110
|
-
|
111
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
112
|
-
of this software and associated documentation files (the "Software"), to
|
113
|
-
deal in the Software without restriction, including without limitation the
|
114
|
-
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
115
|
-
sell copies of the Software, and to permit persons to whom the Software is
|
116
|
-
furnished to do so, subject to the following conditions:
|
117
|
-
|
118
|
-
The above copyright notice and this permission notice shall be included in
|
119
|
-
all copies or substantial portions of the Software.
|
120
|
-
|
121
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
122
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
123
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
124
|
-
THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
125
|
-
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
126
|
-
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|