rack-cache 1.2 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/Rakefile
DELETED
@@ -1,139 +0,0 @@
|
|
1
|
-
require 'rake/clean'
|
2
|
-
|
3
|
-
task :default => [:setup, :test]
|
4
|
-
|
5
|
-
CLEAN.include %w[coverage/ doc/api tags]
|
6
|
-
CLOBBER.include %w[dist]
|
7
|
-
|
8
|
-
desc "Install gem dependencies"
|
9
|
-
task :setup do
|
10
|
-
sh "bundle check >/dev/null || bundle install", :verbose => false
|
11
|
-
end
|
12
|
-
|
13
|
-
# SPECS =====================================================================
|
14
|
-
|
15
|
-
desc 'Run specs with unit test style output'
|
16
|
-
task :test => FileList['test/*_test.rb'] do |t|
|
17
|
-
suite = t.prerequisites
|
18
|
-
sh "bundle exec bacon -q -I.:lib:test #{suite.join(' ')}", :verbose => false
|
19
|
-
end
|
20
|
-
|
21
|
-
desc 'Run specs with story style output'
|
22
|
-
task :spec => FileList['test/*_test.rb'] do |t|
|
23
|
-
suite = t.prerequisites
|
24
|
-
sh "bundle exec bacon -I.:lib:test #{suite.join(' ')}", :verbose => false
|
25
|
-
end
|
26
|
-
|
27
|
-
desc 'Generate test coverage report'
|
28
|
-
task :rcov do
|
29
|
-
sh "rcov -I.:lib:test test/*_test.rb"
|
30
|
-
end
|
31
|
-
|
32
|
-
# DOC =======================================================================
|
33
|
-
desc 'Build all documentation'
|
34
|
-
task :doc => %w[doc:api doc:markdown]
|
35
|
-
|
36
|
-
# requires the hanna gem:
|
37
|
-
# gem install mislav-hanna --source=http://gems.github.com
|
38
|
-
desc 'Build API documentation (doc/api)'
|
39
|
-
task 'doc:api' => 'doc/api/index.html'
|
40
|
-
file 'doc/api/index.html' => FileList['lib/**/*.rb'] do |f|
|
41
|
-
rm_rf 'doc/api'
|
42
|
-
sh((<<-SH).gsub(/[\s\n]+/, ' ').strip)
|
43
|
-
hanna
|
44
|
-
--op doc/api
|
45
|
-
--promiscuous
|
46
|
-
--charset utf8
|
47
|
-
--fmt html
|
48
|
-
--inline-source
|
49
|
-
--line-numbers
|
50
|
-
--accessor option_accessor=RW
|
51
|
-
--main Rack::Cache
|
52
|
-
--title 'Rack::Cache API Documentation'
|
53
|
-
#{f.prerequisites.join(' ')}
|
54
|
-
SH
|
55
|
-
end
|
56
|
-
CLEAN.include 'doc/api'
|
57
|
-
|
58
|
-
desc 'Build markdown documentation files'
|
59
|
-
task 'doc:markdown'
|
60
|
-
FileList['doc/*.markdown'].each do |source|
|
61
|
-
dest = "doc/#{File.basename(source, '.markdown')}.html"
|
62
|
-
file dest => [source, 'doc/layout.html.erb'] do |f|
|
63
|
-
puts "markdown: #{source} -> #{dest}" if verbose
|
64
|
-
require 'erb' unless defined? ERB
|
65
|
-
require 'rdiscount' unless defined? RDiscount
|
66
|
-
template = File.read(source)
|
67
|
-
content = Markdown.new(ERB.new(template, 0, "%<>").result(binding), :smart).to_html
|
68
|
-
title = content.match("<h1>(.*)</h1>")[1] rescue ''
|
69
|
-
layout = ERB.new(File.read("doc/layout.html.erb"), 0, "%<>")
|
70
|
-
output = layout.result(binding)
|
71
|
-
File.open(dest, 'w') { |io| io.write(output) }
|
72
|
-
end
|
73
|
-
task 'doc:markdown' => dest
|
74
|
-
CLEAN.include dest
|
75
|
-
end
|
76
|
-
|
77
|
-
desc 'Publish documentation'
|
78
|
-
task 'doc:publish' => :doc do
|
79
|
-
sh 'rsync -avz doc/ gus@tomayko.com:/src/rack-cache'
|
80
|
-
end
|
81
|
-
|
82
|
-
desc 'Start the documentation development server (requires thin)'
|
83
|
-
task 'doc:server' do
|
84
|
-
sh 'cd doc && thin --rackup server.ru --port 3035 start'
|
85
|
-
end
|
86
|
-
|
87
|
-
# PACKAGING =================================================================
|
88
|
-
|
89
|
-
if defined?(Gem)
|
90
|
-
# load gemspec
|
91
|
-
$spec = eval(File.read('rack-cache.gemspec'))
|
92
|
-
|
93
|
-
def package(ext='')
|
94
|
-
"dist/rack-cache-#{$spec.version}" + ext
|
95
|
-
end
|
96
|
-
|
97
|
-
desc 'Build packages'
|
98
|
-
task :package => %w[.gem .tar.gz].map {|e| package(e)}
|
99
|
-
|
100
|
-
desc 'Build and install as local gem'
|
101
|
-
task :install => package('.gem') do
|
102
|
-
sh "gem install #{package('.gem')}"
|
103
|
-
end
|
104
|
-
|
105
|
-
directory 'dist/'
|
106
|
-
|
107
|
-
file package('.gem') => %w[dist/ rack-cache.gemspec] + $spec.files do |f|
|
108
|
-
sh "gem build rack-cache.gemspec"
|
109
|
-
mv File.basename(f.name), f.name
|
110
|
-
end
|
111
|
-
|
112
|
-
file package('.tar.gz') => %w[dist/] + $spec.files do |f|
|
113
|
-
sh "git archive --format=tar HEAD | gzip > #{f.name}"
|
114
|
-
end
|
115
|
-
|
116
|
-
desc 'Upload gem to gemcutter.org'
|
117
|
-
task 'release' => [package('.gem')] do |t|
|
118
|
-
sh "gem push #{package('.gem')}"
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
# GEMSPEC ===================================================================
|
123
|
-
|
124
|
-
file 'rack-cache.gemspec' => FileList['{lib,test}/**','Rakefile'] do |f|
|
125
|
-
# read spec file and split out manifest section
|
126
|
-
spec = File.read(f.name)
|
127
|
-
parts = spec.split(" # = MANIFEST =\n")
|
128
|
-
fail 'bad spec' if parts.length != 3
|
129
|
-
# determine file list from git ls-files
|
130
|
-
files = `git ls-files`.
|
131
|
-
split("\n").sort.reject{ |file| file =~ /^\./ }.
|
132
|
-
map{ |file| " #{file}" }.join("\n")
|
133
|
-
# piece file back together and write...
|
134
|
-
parts[1] = " s.files = %w[\n#{files}\n ]\n"
|
135
|
-
spec = parts.join(" # = MANIFEST =\n")
|
136
|
-
spec.sub!(/s.date = '.*'/, "s.date = '#{Time.now.strftime("%Y-%m-%d")}'")
|
137
|
-
File.open(f.name, 'w') { |io| io.write(spec) }
|
138
|
-
puts "updated #{f.name}"
|
139
|
-
end
|
data/TODO
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
## 0.5
|
2
|
-
|
3
|
-
- Document allow_revalidate and allow_reload options.
|
4
|
-
- Support multiple memcache servers.
|
5
|
-
- Purge/invalidate everything
|
6
|
-
- Explicit expiration/invalidation based on response headers or via an
|
7
|
-
object interface passed in the rack env.
|
8
|
-
- Sample apps: Rack, Rails, Sinatra, Merb, etc.
|
9
|
-
- Move old breakers.rb configuration file into rack-contrib as a
|
10
|
-
middleware component.
|
11
|
-
|
12
|
-
## Backlog
|
13
|
-
|
14
|
-
- Use Bacon instead of test/spec
|
15
|
-
- Fast path pass processing. We do a lot more than necessary just to determine
|
16
|
-
that the response should be passed through untouched.
|
17
|
-
- Invalidate at the URI of the Location or Content-Location response header
|
18
|
-
on POST, PUT, or DELETE that results in a redirect.
|
19
|
-
- Maximum size of cached entity
|
20
|
-
- Last-Modified factor: requests that have a Last-Modified header but no Expires
|
21
|
-
header have a TTL assigned based on the last modified age of the response:
|
22
|
-
TTL = (Age * Factor), or, 1h = (10h * 0.1)
|
23
|
-
- Consider implementing ESI (http://www.w3.org/TR/esi-lang). This should
|
24
|
-
probably be implemented as a separate middleware component.
|
25
|
-
- stale-while-revalidate
|
26
|
-
- Serve cached copies when down (see: stale-if-error) - e.g., database
|
27
|
-
connection drops and the cache takes over what it can.
|
data/doc/configuration.markdown
DELETED
@@ -1,127 +0,0 @@
|
|
1
|
-
Configuration
|
2
|
-
=============
|
3
|
-
|
4
|
-
__Rack::Cache__ includes a configuration system that can be used to specify
|
5
|
-
fairly sophisticated cache policy on a global or per-request basis.
|
6
|
-
|
7
|
-
<a id='setopt'></a>
|
8
|
-
|
9
|
-
Setting Cache Options
|
10
|
-
---------------------
|
11
|
-
|
12
|
-
Cache options can be set when the __Rack::Cache__ object is created,
|
13
|
-
or by setting a `rack-cache.<option>` variable in __Rack__'s
|
14
|
-
__Environment__.
|
15
|
-
|
16
|
-
When the __Rack::Cache__ object is instantiated:
|
17
|
-
|
18
|
-
use Rack::Cache,
|
19
|
-
:verbose => true,
|
20
|
-
:metastore => 'memcached://localhost:11211/',
|
21
|
-
:entitystore => 'file:/var/cache/rack'
|
22
|
-
|
23
|
-
Using __Rack__'s __Environment__:
|
24
|
-
|
25
|
-
env.merge!(
|
26
|
-
'rack-cache.verbose' => true,
|
27
|
-
'rack-cache.metastore' => 'memcached://localhost:11211/',
|
28
|
-
'rack-cache.entitystore' => 'file:/var/cache/rack'
|
29
|
-
)
|
30
|
-
|
31
|
-
<a id='options'></a>
|
32
|
-
|
33
|
-
Cache Option Reference
|
34
|
-
----------------------
|
35
|
-
|
36
|
-
Use the following options to customize __Rack::Cache__:
|
37
|
-
|
38
|
-
### `verbose`
|
39
|
-
|
40
|
-
Boolean specifying whether verbose trace logging is enabled. This option is
|
41
|
-
currently enabled (`true`) by default but is likely to be disabled (`false`) in
|
42
|
-
a future release. All log output is written to the `rack.errors` stream, which
|
43
|
-
is typically set to `STDERR`.
|
44
|
-
|
45
|
-
The `trace`, `info`, `warn`, and `error` methods can be used within the
|
46
|
-
configuration context to write messages to the errors stream.
|
47
|
-
|
48
|
-
### `default_ttl`
|
49
|
-
|
50
|
-
An integer specifying the number of seconds a cached object should be considered
|
51
|
-
"fresh" when no explicit freshness information is provided in a response.
|
52
|
-
Explicit `Cache-Control` or `Expires` response headers always override this
|
53
|
-
value. The `default_ttl` option defaults to `0`, meaning responses without
|
54
|
-
explicit freshness information are considered immediately "stale" and will not
|
55
|
-
be served from cache without validation.
|
56
|
-
|
57
|
-
### `metastore`
|
58
|
-
|
59
|
-
A URI specifying the __MetaStore__ implementation used to store request/response
|
60
|
-
meta information. See the [Rack::Cache Storage Documentation](storage.html)
|
61
|
-
for detailed information on different storage implementations.
|
62
|
-
|
63
|
-
If no metastore is specified, the `heap:/` store is assumed. This implementation
|
64
|
-
has significant draw-backs so explicit configuration is recommended.
|
65
|
-
|
66
|
-
### `entitystore`
|
67
|
-
|
68
|
-
A URI specifying the __EntityStore__ implementation used to store
|
69
|
-
response bodies. See the [Rack::Cache Storage Documentation](storage.html)
|
70
|
-
for detailed information on different storage implementations.
|
71
|
-
|
72
|
-
If no entitystore is specified, the `heap:/` store is assumed. This
|
73
|
-
implementation has significant draw-backs so explicit configuration is
|
74
|
-
recommended.
|
75
|
-
|
76
|
-
### `private_headers`
|
77
|
-
|
78
|
-
An array of request header names that cause the response to be treated with
|
79
|
-
private cache control semantics. The default value is `['Authorization', 'Cookie']`.
|
80
|
-
If any of these headers are present in the request, the response is considered
|
81
|
-
private and will not be cached _unless_ the response is explicitly marked public
|
82
|
-
(e.g., `Cache-Control: public`).
|
83
|
-
|
84
|
-
### `allow_reload`
|
85
|
-
|
86
|
-
A boolean specifying whether reload requests sent by the client should be
|
87
|
-
honored by the cache. When this option is enabled (`rack-cache.allow_reload`
|
88
|
-
is `true`), requests that include a `Cache-Control: no-cache` header cause
|
89
|
-
the cache to discard anything it has stored for the request and ask that the
|
90
|
-
response be fully generated.
|
91
|
-
|
92
|
-
Most browsers include a `Cache-Control: no-cache` header when the user performs
|
93
|
-
a "hard refresh" (e.g., holding `Shift` while clicking the "Refresh" button).
|
94
|
-
|
95
|
-
*IMPORTANT: Enabling this option globally allows all clients to break your cache.*
|
96
|
-
|
97
|
-
### `allow_revalidate`
|
98
|
-
|
99
|
-
A boolean specifying whether revalidate requests sent by the client should be
|
100
|
-
honored by the cache. When this option is enabled (`rack-cache.allow_revalidate`
|
101
|
-
is `true`), requests that include a `Cache-Control: max-age=0` header cause the
|
102
|
-
cache to assume its copy of the response is stale, resulting in a conditional
|
103
|
-
GET / validation request to be sent to the server.
|
104
|
-
|
105
|
-
Most browsers include a `Cache-Control: max-age=0` header when the user performs
|
106
|
-
a refresh (e.g., clicking the "Refresh" button).
|
107
|
-
|
108
|
-
*IMPORTANT: Enabling this option globally allows all clients to break your cache.*
|
109
|
-
|
110
|
-
### `cache_key`
|
111
|
-
|
112
|
-
A custom cache key generator, which can be anything that responds to :call.
|
113
|
-
By default, this is the `Rack::Cache::Key` class, but you can implement your own
|
114
|
-
generator. A cache key generator gets passed a `Rack::Request` object and generates
|
115
|
-
the appropriate cache key.
|
116
|
-
|
117
|
-
The `Rack::Cache::Key` class by default returns the fully qualified url of the request.
|
118
|
-
|
119
|
-
In addition to setting the generator to an object, you can just pass a block instead,
|
120
|
-
which will act as the cache key generator:
|
121
|
-
|
122
|
-
set :cache_key do |request|
|
123
|
-
request.fullpath.replace(/\//, '-')
|
124
|
-
end
|
125
|
-
|
126
|
-
For more options see the [Rack::Request documentation](http://rack.rubyforge.org/doc/classes/Rack/Request.html)
|
127
|
-
|
data/doc/faq.markdown
DELETED
@@ -1,148 +0,0 @@
|
|
1
|
-
Frequently Asked Questions
|
2
|
-
==========================
|
3
|
-
|
4
|
-
<p class='intro'>
|
5
|
-
<strong>NOTE:</strong> This is a work in progress. Please send questions, comments, or
|
6
|
-
suggestions to <a href="mailto:r@tomayko.com">r@tomayko.com</a>.
|
7
|
-
</p>
|
8
|
-
|
9
|
-
General
|
10
|
-
-------
|
11
|
-
|
12
|
-
|
13
|
-
<a class='hash' id='rails' href='#rails'>#</a>
|
14
|
-
|
15
|
-
### Q: Can I use Rack::Cache with Rails?
|
16
|
-
|
17
|
-
Rack::Cache can be used with Rails 2.3 or above. Documentation and a
|
18
|
-
sample application is forthcoming; in the mean time, see
|
19
|
-
[this example of using Rack::Cache with Rails 2.3](http://snippets.aktagon.com/snippets/302-How-to-setup-and-use-Rack-Cache-with-Rails-2-3-0-RC-1).
|
20
|
-
|
21
|
-
<a class='hash' id='why-not-squid' href='#why-not-squid'>#</a>
|
22
|
-
|
23
|
-
### Q: Why Rack::Cache? Why not Squid, Varnish, Perlbol, etc.?
|
24
|
-
|
25
|
-
__Rack::Cache__ is often easier to setup as part of your existing Ruby
|
26
|
-
application than a separate caching system. __Rack::Cache__ runs entirely inside
|
27
|
-
your backend application processes - no separate / external process is required.
|
28
|
-
This lets __Rack::Cache__ scale down to development environments and simple
|
29
|
-
deployments very easily while not sacrificing the benefits of a standards-based
|
30
|
-
approach to caching.
|
31
|
-
|
32
|
-
|
33
|
-
<a class='hash' id='why-not-rails' href='#why-not-rails'>#</a>
|
34
|
-
|
35
|
-
### Q: Why Rack::Cache? Why not use Rails/Merb/FrameworkX's caching system?
|
36
|
-
|
37
|
-
__Rack::Cache__ takes a standards-based approach to caching that provides some
|
38
|
-
benefits over framework-integrated systems. It uses standard HTTP headers
|
39
|
-
(`Expires`, `Cache-Control`, `Etag`, `Last-Modified`, etc.) to determine
|
40
|
-
what/when to cache. Designing applications to support these standard HTTP
|
41
|
-
mechanisms gives the benefit of being able to switch to a different HTTP
|
42
|
-
cache implementation in the future.
|
43
|
-
|
44
|
-
In addition, using a standards-based approach to caching creates a clear
|
45
|
-
separation between application and caching logic. The application need only
|
46
|
-
specify a basic set of information about the response and all decisions
|
47
|
-
regarding how and when to cache is moved into the caching layer.
|
48
|
-
|
49
|
-
|
50
|
-
<a class='hash' id='scale' href='#scale'>#</a>
|
51
|
-
|
52
|
-
### Q: Will Rack::Cache make my app scale?
|
53
|
-
|
54
|
-
No. Your design is the only thing that can make your app scale.
|
55
|
-
|
56
|
-
Also, __Rack::Cache__ is not overly optimized for performance. The main goal of
|
57
|
-
the project is to provide a portable, easy-to-configure, and standards-based
|
58
|
-
caching solution for small to medium sized deployments. More sophisticated /
|
59
|
-
performant caching systems (e.g., [Varnish][v], [Squid][s],
|
60
|
-
[httpd/mod-cache][h]) may be more appropriate for large deployments with
|
61
|
-
crazy-land throughput requirements.
|
62
|
-
|
63
|
-
[v]: http://varnish.projects.linpro.no/
|
64
|
-
[s]: http://www.squid-cache.org/
|
65
|
-
[h]: http://httpd.apache.org/docs/2.0/mod/mod_cache.html
|
66
|
-
|
67
|
-
|
68
|
-
Features
|
69
|
-
--------
|
70
|
-
|
71
|
-
|
72
|
-
<a class='hash' id='validation' href='#validation'>#</a>
|
73
|
-
|
74
|
-
### Q: Does Rack::Cache support validation?
|
75
|
-
|
76
|
-
Yes. Both freshness and validation-based caching is supported. A response
|
77
|
-
will be cached if it has a freshness lifetime (e.g., `Expires` or
|
78
|
-
`Cache-Control: max-age=N` headers) and/or includes a validator (e.g.,
|
79
|
-
`Last-Modified` or `ETag` headers). When the cache hits and the response is
|
80
|
-
fresh, it's delivered immediately without talking to the backend application;
|
81
|
-
when the cache is stale, the cached response is validated using a conditional
|
82
|
-
GET request.
|
83
|
-
|
84
|
-
|
85
|
-
<a class='hash' id='fragments' href='#fragments'>#</a>
|
86
|
-
|
87
|
-
### Q: Does Rack::Cache support fragment caching?
|
88
|
-
|
89
|
-
Not really. __Rack::Cache__ deals with entire responses and doesn't know
|
90
|
-
anything about how your application constructs them.
|
91
|
-
|
92
|
-
However, something like [ESI](http://www.w3.org/TR/esi-lang) may be implemented
|
93
|
-
in the future (likely as a separate Rack middleware component that could be
|
94
|
-
situated upstream from Rack::Cache), which would allow applications to compose
|
95
|
-
responses based on several "fragment resources". Each fragment would have its
|
96
|
-
own cache policy.
|
97
|
-
|
98
|
-
|
99
|
-
<a class='hash' id='manual-purge' href='#manual-purge'>#</a>
|
100
|
-
|
101
|
-
### Q: How do I manually purge or expire a cached entry?
|
102
|
-
|
103
|
-
Although planned, there is currently no mechanism for manually purging
|
104
|
-
an entry stored in the cache.
|
105
|
-
|
106
|
-
Note that using an `Expires` or `Cache-Control: max-age=N` header and relying on
|
107
|
-
manual purge to invalidate cached entry can often be implemented more simply
|
108
|
-
using efficient validation based caching (`Last-Modified`, `Etag`). Many web
|
109
|
-
frameworks are based entirely on manual purge and do not support validation at
|
110
|
-
the cache level.
|
111
|
-
|
112
|
-
|
113
|
-
<a class='hash' id='force-pass' href='#force-pass'>#</a>
|
114
|
-
|
115
|
-
### Q: How do I bypass rack-cache on a per-request basis?
|
116
|
-
|
117
|
-
Set the `rack-cache.force-pass` variable in the rack environment to `true`.
|
118
|
-
|
119
|
-
|
120
|
-
<a class='hash' id='efficient-validation' href='#efficient-validation'>#</a>
|
121
|
-
|
122
|
-
### Q: What does "Efficient Validation" mean?
|
123
|
-
|
124
|
-
It means that your application performs only the processing necessary to
|
125
|
-
determine if a response is valid before sending a `304 Not Modified` in response
|
126
|
-
to a conditional GET request. Many applications that perform validation do so
|
127
|
-
only after the entire response has been generated, which provides bandwidth
|
128
|
-
savings but results in no CPU/IO savings. Implementing validation efficiently
|
129
|
-
can increase backend application throughput significantly when fronted by a
|
130
|
-
validating caching system (like __Rack::Cache__).
|
131
|
-
|
132
|
-
[Here's an example Rack application](http://gist.github.com/9395) that performs
|
133
|
-
efficient validation.
|
134
|
-
|
135
|
-
|
136
|
-
<a class='hash' id='orly' href='#orly'>#</a>
|
137
|
-
|
138
|
-
### Q: Did you just make that up?
|
139
|
-
|
140
|
-
Yes.
|
141
|
-
|
142
|
-
|
143
|
-
<a class='hash' id='https' href='#https'>#</a>
|
144
|
-
|
145
|
-
### Q: Can I do HTTPS with Rack::Cache?
|
146
|
-
|
147
|
-
Sure. HTTPS is typically managed by a front-end web server so this isn't really
|
148
|
-
relevant to Rack::Cache.
|
data/doc/index.markdown
DELETED
@@ -1,121 +0,0 @@
|
|
1
|
-
__Rack::Cache__ is suitable as a quick drop-in component to enable HTTP caching
|
2
|
-
for [Rack][]-based applications that produce freshness (`Expires`,
|
3
|
-
`Cache-Control`) and/or validation (`Last-Modified`, `ETag`) information.
|
4
|
-
|
5
|
-
* Standards-based (see [RFC 2616][rfc] / [Section 13][s13]).
|
6
|
-
* Freshness/expiration based caching
|
7
|
-
* Validation
|
8
|
-
* Vary support
|
9
|
-
* Portable: 100% Ruby / works with any [Rack][]-enabled framework.
|
10
|
-
* Disk, memcached, and heap memory [storage backends][storage].
|
11
|
-
|
12
|
-
News
|
13
|
-
----
|
14
|
-
|
15
|
-
* Rack::Cache 1.0 was released on December 24, 2010. See the
|
16
|
-
[`CHANGES`](http://github.com/rtomayko/rack-cache/blob/1.0/CHANGES) file
|
17
|
-
for details.
|
18
|
-
* [How to use Rack::Cache with Rails 2.3](http://snippets.aktagon.com/snippets/302-How-to-setup-and-use-Rack-Cache-with-Rails-2-3-0-RC-1) - it's really easy.
|
19
|
-
* [RailsLab's Advanced HTTP Caching Screencast](http://railslab.newrelic.com/2009/02/26/episode-11-advanced-http-caching)
|
20
|
-
is a really great review of HTTP caching concepts and shows how to
|
21
|
-
use Rack::Cache with Rails.
|
22
|
-
|
23
|
-
Installation
|
24
|
-
------------
|
25
|
-
|
26
|
-
$ sudo gem install rack-cache
|
27
|
-
|
28
|
-
Or, from a local working copy:
|
29
|
-
|
30
|
-
$ git clone git://github.com/rtomayko/rack-cache.git
|
31
|
-
$ rake package && sudo rake install
|
32
|
-
|
33
|
-
Basic Usage
|
34
|
-
-----------
|
35
|
-
|
36
|
-
__Rack::Cache__ is implemented as a piece of [Rack][] middleware and can be used
|
37
|
-
with any __Rack__-based application. If your application includes a rackup
|
38
|
-
(`.ru`) file or uses __Rack::Builder__ to construct the application pipeline,
|
39
|
-
simply `require` and `use` as follows:
|
40
|
-
|
41
|
-
require 'rack/cache'
|
42
|
-
|
43
|
-
use Rack::Cache,
|
44
|
-
:verbose => true,
|
45
|
-
:metastore => 'file:/var/cache/rack/meta',
|
46
|
-
:entitystore => 'file:/var/cache/rack/body'
|
47
|
-
|
48
|
-
run app
|
49
|
-
|
50
|
-
Assuming you've designed your backend application to take advantage of HTTP's
|
51
|
-
caching features, no further code or configuration is required for basic
|
52
|
-
caching.
|
53
|
-
|
54
|
-
More
|
55
|
-
----
|
56
|
-
|
57
|
-
* [Configuration Options][config] - how to set cache options.
|
58
|
-
|
59
|
-
* [Cache Storage Documentation][storage] - detailed information on the various
|
60
|
-
storage implementations available in __Rack::Cache__ and how to choose the one
|
61
|
-
that's best for your application.
|
62
|
-
|
63
|
-
* [Things Caches Do][things] - an illustrated guide to how HTTP gateway
|
64
|
-
caches work with pointers to other useful resources on HTTP caching.
|
65
|
-
|
66
|
-
* [GitHub Repository](http://github.com/rtomayko/rack-cache/) - get your
|
67
|
-
fork on.
|
68
|
-
|
69
|
-
* [Mailing List](http://groups.google.com/group/rack-cache) - for hackers
|
70
|
-
and users (`rack-cache@groups.google.com`).
|
71
|
-
|
72
|
-
* [FAQ](./faq) - Frequently Asked Questions about __Rack::Cache__.
|
73
|
-
|
74
|
-
* [RDoc API Documentation](./api/) - Mostly worthless if you just want to use
|
75
|
-
__Rack::Cache__ in your application but mildly insightful if you'd like to
|
76
|
-
get a feel for how the system has been put together; I recommend
|
77
|
-
[reading the source](http://github.com/rtomayko/rack-cache/tree/master/lib/rack/cache).
|
78
|
-
|
79
|
-
|
80
|
-
See Also
|
81
|
-
--------
|
82
|
-
|
83
|
-
The overall design of __Rack::Cache__ is based largely on the work of the
|
84
|
-
internet standards community. The following resources provide a good starting
|
85
|
-
point for exploring the basic concepts of HTTP caching:
|
86
|
-
|
87
|
-
* Mark Nottingham's [Caching Tutorial](http://www.mnot.net/cache_docs/),
|
88
|
-
especially the short section on
|
89
|
-
[How Web Caches Work](http://www.mnot.net/cache_docs/#WORK)
|
90
|
-
|
91
|
-
* Joe Gregorio's [Doing HTTP Caching Right](http://www.xml.com/lpt/a/1642)
|
92
|
-
|
93
|
-
* [RFC 2616](http://www.ietf.org/rfc/rfc2616.txt), especially
|
94
|
-
[Section 13, "Caching in HTTP"](http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html)
|
95
|
-
|
96
|
-
__Rack::Cache__ takes (_liberally_) various concepts from
|
97
|
-
[Varnish](http://varnish.projects.linpro.no/) and
|
98
|
-
[Django's cache framework](http://docs.djangoproject.com/en/dev/topics/cache/).
|
99
|
-
|
100
|
-
License
|
101
|
-
-------
|
102
|
-
|
103
|
-
__Rack::Cache__ is Copyright © 2008
|
104
|
-
by [Ryan Tomayko](http://tomayko.com/about)
|
105
|
-
and is provided under [the MIT license](./license)
|
106
|
-
|
107
|
-
[config]: ./configuration "Rack::Cache Configuration Language Documentation"
|
108
|
-
[storage]: ./storage "Rack::Cache Storage Documentation"
|
109
|
-
[things]: http://tomayko.com/writings/things-caches-do
|
110
|
-
|
111
|
-
[rfc]: http://tools.ietf.org/html/rfc2616
|
112
|
-
"RFC 2616 - Hypertext Transfer Protocol -- HTTP/1.1 [ietf.org]"
|
113
|
-
|
114
|
-
[s13]: http://tools.ietf.org/html/rfc2616#section-13
|
115
|
-
"RFC 2616 / Section 13 Caching in HTTP"
|
116
|
-
|
117
|
-
[rack]: http://rack.rubyforge.org/
|
118
|
-
"Rack: a Ruby Webserver Interface"
|
119
|
-
|
120
|
-
[vcl]: http://tomayko.com/man/vcl
|
121
|
-
"VCL(7) -- Varnish Configuration Language Manual Page"
|
data/doc/layout.html.erb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html lang='en'>
|
3
|
-
<head>
|
4
|
-
<meta http-equiv='Content-Type' content='text/html;charset=utf-8'>
|
5
|
-
<title>Rack::Cache <%= title %></title>
|
6
|
-
<link rel='stylesheet' href='rack-cache.css' type='text/css' media='all'>
|
7
|
-
<script type='text/javascript' src='http://code.jquery.com/jquery-1.2.3.js'></script>
|
8
|
-
<script type='text/javascript' src='http://tomayko.com/js/tomayko.js'></script>
|
9
|
-
</head>
|
10
|
-
<body>
|
11
|
-
<div id='container'>
|
12
|
-
<div id='header'>
|
13
|
-
<h1><a href="./">rack-cache</a></h1>
|
14
|
-
<p>
|
15
|
-
<a href="./configuration" title='Configuration Language Documentation'>Config</a> |
|
16
|
-
<a href="./storage" title='Cache Storage Documentation'>Storage</a> |
|
17
|
-
<a href="http://tomayko.com/writings/things-caches-do" title="Things Caches Do">Things</a> |
|
18
|
-
<a href="./faq" title='Frequently Asked Questions'>FAQ</a> |
|
19
|
-
<a href="./api/" title='Fucking Sucks.'>RDoc</a>
|
20
|
-
</p>
|
21
|
-
</div>
|
22
|
-
<div id='content'><%= content %></div>
|
23
|
-
<div id='footer'>
|
24
|
-
<p class='rights'>
|
25
|
-
Copyright
|
26
|
-
<a href="./license" rel="license">©</a>
|
27
|
-
2003-2008
|
28
|
-
by
|
29
|
-
<a href='http://tomayko.com/about' rel='me author'>Ryan Tomayko</a>
|
30
|
-
</p>
|
31
|
-
</div>
|
32
|
-
</div>
|
33
|
-
</body>
|
34
|
-
</html>
|
data/doc/license.markdown
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
License (MIT)
|
2
|
-
=============
|
3
|
-
|
4
|
-
__Rack::Cache__ is Copyright © 2008
|
5
|
-
by [Ryan Tomayko](http://tomayko.com/about)
|
6
|
-
|
7
|
-
<pre class='license'>
|
8
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
-
of this software and associated documentation files (the "Software"), to
|
10
|
-
deal in the Software without restriction, including without limitation the
|
11
|
-
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
12
|
-
sell copies of the Software, and to permit persons to whom the Software is
|
13
|
-
furnished to do so, subject to the following conditions:
|
14
|
-
|
15
|
-
The above copyright notice and this permission notice shall be included in
|
16
|
-
all copies or substantial portions of the Software.
|
17
|
-
|
18
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
21
|
-
THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
22
|
-
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
23
|
-
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
24
|
-
</pre>
|