rack-cache 0.5.3 → 1.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rack-cache might be problematic. Click here for more details.
- data/CHANGES +25 -1
- data/README +16 -0
- data/lib/rack/cache/cachecontrol.rb +4 -3
- data/lib/rack/cache/entitystore.rb +5 -5
- data/lib/rack/cache/metastore.rb +4 -4
- data/lib/rack/cache/storage.rb +3 -3
- data/rack-cache.gemspec +4 -3
- data/test/cachecontrol_test.rb +6 -0
- data/test/entitystore_test.rb +4 -4
- data/test/metastore_test.rb +4 -4
- data/test/spec_setup.rb +16 -16
- metadata +33 -6
data/CHANGES
CHANGED
@@ -1,4 +1,28 @@
|
|
1
|
-
##
|
1
|
+
## 1.0 / December 2010
|
2
|
+
|
3
|
+
* Rack::Cache is 1.0 and will now maintain semantic versioning <http://semver.org/>
|
4
|
+
|
5
|
+
* Add Dalli memcache client support and removed support for the unmaintained
|
6
|
+
memcache-client library. You will need to move your apps to Dalli before
|
7
|
+
upgrading rack-cache to 1.0.
|
8
|
+
|
9
|
+
## 0.5.3 / September 2010
|
10
|
+
|
11
|
+
* A matching If-Modified-Since is ignored if an If-None-Match is also provided
|
12
|
+
and doesn't match. This is in line with RFC 2616.
|
13
|
+
|
14
|
+
* Converts string status codes to integers before returns to workaround bad
|
15
|
+
behaving rack middleware and apps.
|
16
|
+
|
17
|
+
* Misc doc clean up.
|
18
|
+
|
19
|
+
## 0.5.2 / September 2009
|
20
|
+
|
21
|
+
* Exceptions raised from the metastore are not fatal. This makes a lot of
|
22
|
+
sense in most cases because its okay for the cache to be down - it
|
23
|
+
shouldn't blow up your app.
|
24
|
+
|
25
|
+
## 0.5.1 / June 2009
|
2
26
|
|
3
27
|
* Added support for memcached clusters and other advanced
|
4
28
|
configuration provided by the memcache-client and memcached
|
data/README
CHANGED
@@ -75,6 +75,22 @@ See the following for more information:
|
|
75
75
|
|
76
76
|
http://snippets.aktagon.com/snippets/302
|
77
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
|
+
|
78
94
|
Links
|
79
95
|
-----
|
80
96
|
|
@@ -182,11 +182,12 @@ module Rack
|
|
182
182
|
private
|
183
183
|
def parse(value)
|
184
184
|
return if value.nil? || value.empty?
|
185
|
-
value.delete(' ').split(',').
|
185
|
+
value.delete(' ').split(',').each do |part|
|
186
|
+
next if part.empty?
|
186
187
|
name, value = part.split('=', 2)
|
187
|
-
|
188
|
-
hash
|
188
|
+
self[name.downcase] = (value || true) unless name.empty?
|
189
189
|
end
|
190
|
+
self
|
190
191
|
end
|
191
192
|
end
|
192
193
|
end
|
@@ -204,16 +204,16 @@ module Rack::Cache
|
|
204
204
|
end
|
205
205
|
end
|
206
206
|
|
207
|
-
# Uses the
|
207
|
+
# Uses the Dalli ruby library. This is the default unless
|
208
208
|
# the memcached library has already been required.
|
209
|
-
class
|
209
|
+
class Dalli < MemCacheBase
|
210
210
|
def initialize(server="localhost:11211", options={})
|
211
211
|
@cache =
|
212
212
|
if server.respond_to?(:stats)
|
213
213
|
server
|
214
214
|
else
|
215
|
-
require '
|
216
|
-
::
|
215
|
+
require 'dalli'
|
216
|
+
::Dalli::Client.new(server, options)
|
217
217
|
end
|
218
218
|
end
|
219
219
|
|
@@ -284,7 +284,7 @@ module Rack::Cache
|
|
284
284
|
if defined?(::Memcached)
|
285
285
|
MemCached
|
286
286
|
else
|
287
|
-
|
287
|
+
Dalli
|
288
288
|
end
|
289
289
|
|
290
290
|
MEMCACHED = MEMCACHE
|
data/lib/rack/cache/metastore.rb
CHANGED
@@ -301,14 +301,14 @@ module Rack::Cache
|
|
301
301
|
end
|
302
302
|
end
|
303
303
|
|
304
|
-
class
|
304
|
+
class Dalli < MemCacheBase
|
305
305
|
def initialize(server="localhost:11211", options={})
|
306
306
|
@cache =
|
307
307
|
if server.respond_to?(:stats)
|
308
308
|
server
|
309
309
|
else
|
310
|
-
require '
|
311
|
-
::
|
310
|
+
require 'dalli'
|
311
|
+
::Dalli::Client.new(server, options)
|
312
312
|
end
|
313
313
|
end
|
314
314
|
|
@@ -368,7 +368,7 @@ module Rack::Cache
|
|
368
368
|
if defined?(::Memcached)
|
369
369
|
MemCached
|
370
370
|
else
|
371
|
-
|
371
|
+
Dalli
|
372
372
|
end
|
373
373
|
MEMCACHED = MEMCACHE
|
374
374
|
|
data/lib/rack/cache/storage.rb
CHANGED
@@ -39,11 +39,11 @@ module Rack::Cache
|
|
39
39
|
fail "Unknown storage provider: #{uri.to_s}"
|
40
40
|
end
|
41
41
|
else
|
42
|
-
# hack in support for passing a
|
42
|
+
# hack in support for passing a Dalli::Client or Memcached object
|
43
43
|
# as the storage URI.
|
44
44
|
case
|
45
|
-
when defined?(::
|
46
|
-
type.const_get(:
|
45
|
+
when defined?(::Dalli) && uri.kind_of?(::Dalli::Client)
|
46
|
+
type.const_get(:Dalli).resolve(uri)
|
47
47
|
when defined?(::Memcached) && uri.respond_to?(:stats)
|
48
48
|
type.const_get(:MemCached).resolve(uri)
|
49
49
|
else
|
data/rack-cache.gemspec
CHANGED
@@ -3,8 +3,8 @@ Gem::Specification.new do |s|
|
|
3
3
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
4
4
|
|
5
5
|
s.name = 'rack-cache'
|
6
|
-
s.version = '0
|
7
|
-
s.date = '2010-
|
6
|
+
s.version = '1.0'
|
7
|
+
s.date = '2010-12-24'
|
8
8
|
|
9
9
|
s.description = "HTTP Caching for Rack"
|
10
10
|
s.summary = "HTTP Caching for Rack"
|
@@ -62,11 +62,12 @@ Gem::Specification.new do |s|
|
|
62
62
|
s.add_dependency 'rack', '>= 0.4'
|
63
63
|
|
64
64
|
s.add_development_dependency 'test-spec'
|
65
|
+
s.add_development_dependency 'memcached'
|
66
|
+
s.add_development_dependency 'dalli'
|
65
67
|
|
66
68
|
s.has_rdoc = true
|
67
69
|
s.homepage = "http://tomayko.com/src/rack-cache/"
|
68
70
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Rack::Cache", "--main", "Rack::Cache"]
|
69
71
|
s.require_paths = %w[lib]
|
70
|
-
s.rubyforge_project = 'wink'
|
71
72
|
s.rubygems_version = '1.1.1'
|
72
73
|
end
|
data/test/cachecontrol_test.rb
CHANGED
@@ -49,6 +49,12 @@ describe 'Rack::Cache::CacheControl' do
|
|
49
49
|
cache_control['max-age'].should.equal '600'
|
50
50
|
end
|
51
51
|
|
52
|
+
it 'strips blank segments' do
|
53
|
+
cache_control = Rack::Cache::CacheControl.new('max-age=600,,max-stale=300')
|
54
|
+
cache_control['max-age'].should.equal '600'
|
55
|
+
cache_control['max-stale'].should.equal '300'
|
56
|
+
end
|
57
|
+
|
52
58
|
it 'removes all directives with #clear' do
|
53
59
|
cache_control = Rack::Cache::CacheControl.new('max-age=600, must-revalidate')
|
54
60
|
cache_control.clear
|
data/test/entitystore_test.rb
CHANGED
@@ -188,12 +188,12 @@ describe 'Rack::Cache::EntityStore' do
|
|
188
188
|
end
|
189
189
|
|
190
190
|
|
191
|
-
|
192
|
-
describe '
|
191
|
+
need_dalli 'entity store tests' do
|
192
|
+
describe 'Dalli' do
|
193
193
|
it_should_behave_like 'A Rack::Cache::EntityStore Implementation'
|
194
194
|
before do
|
195
|
-
$
|
196
|
-
@store = Rack::Cache::EntityStore::
|
195
|
+
$dalli.flush_all
|
196
|
+
@store = Rack::Cache::EntityStore::Dalli.new($dalli)
|
197
197
|
end
|
198
198
|
after do
|
199
199
|
@store = nil
|
data/test/metastore_test.rb
CHANGED
@@ -261,13 +261,13 @@ describe 'Rack::Cache::MetaStore' do
|
|
261
261
|
end
|
262
262
|
end
|
263
263
|
|
264
|
-
|
265
|
-
describe '
|
264
|
+
need_dalli 'metastore tests' do
|
265
|
+
describe 'Dalli' do
|
266
266
|
it_should_behave_like 'A Rack::Cache::MetaStore Implementation'
|
267
267
|
before :each do
|
268
268
|
@temp_dir = create_temp_directory
|
269
|
-
$
|
270
|
-
@store = Rack::Cache::MetaStore::
|
269
|
+
$dalli.flush_all
|
270
|
+
@store = Rack::Cache::MetaStore::Dalli.new($dalli)
|
271
271
|
@entity_store = Rack::Cache::EntityStore::Heap.new
|
272
272
|
end
|
273
273
|
end
|
data/test/spec_setup.rb
CHANGED
@@ -15,7 +15,7 @@ end
|
|
15
15
|
# of the MemCached meta and entity stores.
|
16
16
|
ENV['MEMCACHED'] ||= 'localhost:11211'
|
17
17
|
$memcached = nil
|
18
|
-
$
|
18
|
+
$dalli = nil
|
19
19
|
|
20
20
|
def have_memcached?(server=ENV['MEMCACHED'])
|
21
21
|
return $memcached unless $memcached.nil?
|
@@ -36,36 +36,36 @@ end
|
|
36
36
|
|
37
37
|
have_memcached?
|
38
38
|
|
39
|
-
def
|
40
|
-
return $
|
41
|
-
require '
|
42
|
-
$
|
43
|
-
$
|
39
|
+
def have_dalli?(server=ENV['MEMCACHED'])
|
40
|
+
return $dalli unless $dalli.nil?
|
41
|
+
require 'dalli'
|
42
|
+
$dalli = Dalli::Client.new(server)
|
43
|
+
$dalli.set('ping', '')
|
44
44
|
true
|
45
45
|
rescue LoadError => boom
|
46
|
-
$
|
46
|
+
$dalli = false
|
47
47
|
false
|
48
48
|
rescue => boom
|
49
|
-
STDERR.puts "
|
50
|
-
$
|
49
|
+
STDERR.puts "dalli not working. related tests will be skipped."
|
50
|
+
$dalli = false
|
51
51
|
false
|
52
52
|
end
|
53
53
|
|
54
|
-
|
54
|
+
have_dalli?
|
55
55
|
|
56
|
-
def
|
57
|
-
if
|
56
|
+
def need_dalli(forwhat)
|
57
|
+
if have_dalli?
|
58
58
|
yield
|
59
59
|
else
|
60
|
-
STDERR.puts "skipping
|
60
|
+
STDERR.puts "skipping Dalli #{forwhat}"
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
-
def
|
65
|
-
if
|
64
|
+
def need_memcached(forwhat)
|
65
|
+
if have_memcached?
|
66
66
|
yield
|
67
67
|
else
|
68
|
-
STDERR.puts "skipping
|
68
|
+
STDERR.puts "skipping memcached #{forwhat}"
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
|
+
- 1
|
7
8
|
- 0
|
8
|
-
|
9
|
-
- 3
|
10
|
-
version: 0.5.3
|
9
|
+
version: "1.0"
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Ryan Tomayko
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2010-
|
17
|
+
date: 2010-12-24 00:00:00 -08:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
@@ -47,6 +46,34 @@ dependencies:
|
|
47
46
|
version: "0"
|
48
47
|
type: :development
|
49
48
|
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: memcached
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
type: :development
|
62
|
+
version_requirements: *id003
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: dalli
|
65
|
+
prerelease: false
|
66
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
type: :development
|
76
|
+
version_requirements: *id004
|
50
77
|
description: HTTP Caching for Rack
|
51
78
|
email: r@tomayko.com
|
52
79
|
executables: []
|
@@ -132,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
159
|
version: "0"
|
133
160
|
requirements: []
|
134
161
|
|
135
|
-
rubyforge_project:
|
162
|
+
rubyforge_project:
|
136
163
|
rubygems_version: 1.3.7
|
137
164
|
signing_key:
|
138
165
|
specification_version: 2
|