rack-cachely 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +2 -3
- data/lib/rack-cachely/config.rb +11 -1
- data/lib/rack-cachely/context.rb +2 -2
- data/lib/rack-cachely/store.rb +3 -3
- data/lib/rack-cachely/version.rb +1 -1
- data/spec/rack-cachely/config_spec.rb +34 -1
- data/spec/rack-cachely/context_spec.rb +49 -2
- data/spec/rack-cachely/store_spec.rb +2 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d5cc375109389743f021cf1f7fb371099ea0131a
|
4
|
+
data.tar.gz: c5871bb7b78afb9d243a5ca315d6dc1cba2a25a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e5d8d6a5106081cb2de26431de63c3fc689471bd6e9075fec3be1c4c581b8fa836cc8aa381310cae89eecef121dc24605b9557cb19b70d437b14456f634245b
|
7
|
+
data.tar.gz: 04459c6d33d29e5e9c19fcd8e4bd969427c27c3c07d4f68034228f669773ff6f1abe94496728c898ee648194921eac77968db9995fc5004ea4a21cc179c283ca
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -18,9 +18,7 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
If you would like to join the private beta, please email [mark+cachely@meta42.com](mailto:mark+cachely@meta42.com)
|
21
|
+
Cachely is currently available only as a Heroku Add-on.
|
24
22
|
|
25
23
|
### Rails 3.x
|
26
24
|
|
@@ -87,4 +85,5 @@ Rack::Cachely::Store.delete("users/\d+")
|
|
87
85
|
## Contributors
|
88
86
|
|
89
87
|
* Mark Bates
|
88
|
+
* Sam Beam
|
90
89
|
* Tim Raymond
|
data/lib/rack-cachely/config.rb
CHANGED
@@ -9,7 +9,17 @@ module Rack
|
|
9
9
|
options.each do |key, value|
|
10
10
|
self.send("#{key}=", value)
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
|
+
url = options[:cachely_url] || ENV["CACHELY_URL"]
|
14
|
+
|
15
|
+
if !url || (url.respond_to?(:empty?) && url.empty?)
|
16
|
+
self.logger.warn("Cachely: config incomplete (cachely_url is missing), disabling cachley.")
|
17
|
+
self.options[:enabled] = false
|
18
|
+
else
|
19
|
+
url = "#{url}/v1/cache"
|
20
|
+
self.options[:enabled] = true
|
21
|
+
end
|
22
|
+
self.cachely_url = url
|
13
23
|
end
|
14
24
|
|
15
25
|
def ignore_query_params=(*args)
|
data/lib/rack-cachely/context.rb
CHANGED
@@ -38,7 +38,7 @@ module Rack
|
|
38
38
|
else
|
39
39
|
@env['rack-cachely.perform_caching'].to_s == 'true'
|
40
40
|
end
|
41
|
-
perform_caching && request.request_method == 'GET' && !request.params["no-cachely"]
|
41
|
+
perform_caching && config.enabled && request.request_method == 'GET' && !request.params["no-cachely"]
|
42
42
|
end
|
43
43
|
|
44
44
|
def is_cacheable?(results)
|
@@ -64,4 +64,4 @@ module Rack
|
|
64
64
|
end
|
65
65
|
|
66
66
|
end
|
67
|
-
end
|
67
|
+
end
|
data/lib/rack-cachely/store.rb
CHANGED
@@ -70,8 +70,8 @@ module Rack
|
|
70
70
|
|
71
71
|
def remote(&block)
|
72
72
|
begin
|
73
|
-
Timeout::timeout(config.timeout, &block)
|
74
|
-
rescue Timeout::Error, Errno::ECONNREFUSED => e
|
73
|
+
::Timeout::timeout(config.timeout, &block)
|
74
|
+
rescue ::Timeout::Error, Errno::ECONNREFUSED => e
|
75
75
|
# raise e
|
76
76
|
logger.error(e)
|
77
77
|
end
|
@@ -87,4 +87,4 @@ module Rack
|
|
87
87
|
|
88
88
|
end
|
89
89
|
end
|
90
|
-
end
|
90
|
+
end
|
data/lib/rack-cachely/version.rb
CHANGED
@@ -21,4 +21,37 @@ describe Rack::Cachely::Config do
|
|
21
21
|
|
22
22
|
end
|
23
23
|
|
24
|
-
|
24
|
+
|
25
|
+
describe "initializer" do
|
26
|
+
|
27
|
+
it "sets cachely_url from ENV" do
|
28
|
+
config.cachely_url.should == "#{ENV['CACHELY_URL']}/v1/cache"
|
29
|
+
end
|
30
|
+
|
31
|
+
it "sets enabled" do
|
32
|
+
config.enabled.should == true
|
33
|
+
end
|
34
|
+
|
35
|
+
context "with no ENV['CACHELY_URL']" do
|
36
|
+
|
37
|
+
before do
|
38
|
+
@old_env = ENV.delete('CACHELY_URL')
|
39
|
+
@logger = mock
|
40
|
+
Rack::Cachely::Config.any_instance.stub(:logger).and_return @logger
|
41
|
+
end
|
42
|
+
|
43
|
+
after do
|
44
|
+
ENV['CACHELY_URL'] = @old_env
|
45
|
+
end
|
46
|
+
|
47
|
+
it "warns and disables if there is no cachely_url" do
|
48
|
+
@logger.should_receive(:warn)
|
49
|
+
config.enabled.should == false
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
end
|
@@ -2,6 +2,53 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Rack::Cachely::Context do
|
4
4
|
|
5
|
-
|
5
|
+
describe 'call' do
|
6
6
|
|
7
|
-
|
7
|
+
let(:app) { mock }
|
8
|
+
let(:context) { Rack::Cachely::Context.new(app) }
|
9
|
+
|
10
|
+
context 'when cachely is disabled in config' do
|
11
|
+
before do
|
12
|
+
Rack::Cachely.config.enabled = false
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'invokes the app' do
|
16
|
+
app.should_receive(:call)
|
17
|
+
context.call({})
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'with cachely enabled in config' do
|
23
|
+
before do
|
24
|
+
Rack::Cachely.config.enabled = true
|
25
|
+
@env = { 'rack-cachely.perform_caching' => true }
|
26
|
+
Rack::Cachely::Store.stub(get: true)
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'without no-cachely param' do
|
30
|
+
before do
|
31
|
+
context.stub(:request => mock(:request_method => 'GET', :params => {}))
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'does not invoke the app' do
|
35
|
+
app.should_not_receive(:call)
|
36
|
+
context.call(@env)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'with no-cachely param' do
|
41
|
+
before do
|
42
|
+
context.stub(:request => mock(:request_method => 'GET', :params => {'no-cachely' => true}))
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'invokes the app' do
|
46
|
+
app.should_receive(:call)
|
47
|
+
context.call(@env)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-cachely
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Bates
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -78,3 +78,4 @@ test_files:
|
|
78
78
|
- spec/rack-cachely/key_spec.rb
|
79
79
|
- spec/rack-cachely/store_spec.rb
|
80
80
|
- spec/spec_helper.rb
|
81
|
+
has_rdoc:
|