padrino-cache 0.10.5 → 0.10.6.a
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/padrino-cache/helpers/page.rb +13 -3
- data/lib/padrino-cache/store/file.rb +4 -3
- data/lib/padrino-cache.rb +1 -1
- data/test/test_padrino_cache.rb +2 -2
- metadata +28 -9
@@ -93,18 +93,28 @@ module Padrino
|
|
93
93
|
began_at = Time.now
|
94
94
|
value = settings.cache.get(@route.cache_key || env['PATH_INFO'])
|
95
95
|
logger.debug "GET Cache", began_at, @route.cache_key || env['PATH_INFO'] if defined?(logger) && value
|
96
|
-
|
96
|
+
|
97
|
+
if value
|
98
|
+
content_type(value[:content_type]) if value[:content_type]
|
99
|
+
halt 200, value[:response_buffer] if value[:response_buffer]
|
100
|
+
end
|
97
101
|
end
|
98
102
|
end
|
99
103
|
|
100
104
|
route.after_filters do
|
101
105
|
if settings.caching?
|
102
106
|
began_at = Time.now
|
107
|
+
|
108
|
+
content = {
|
109
|
+
:response_buffer => @_response_buffer,
|
110
|
+
:content_type => @_content_type
|
111
|
+
}
|
112
|
+
|
103
113
|
if @_last_expires_in
|
104
|
-
settings.cache.set(@route.cache_key || env['PATH_INFO'],
|
114
|
+
settings.cache.set(@route.cache_key || env['PATH_INFO'], content, :expires_in => @_last_expires_in)
|
105
115
|
@_last_expires_in = nil
|
106
116
|
else
|
107
|
-
settings.cache.set(@route.cache_key || env['PATH_INFO'],
|
117
|
+
settings.cache.set(@route.cache_key || env['PATH_INFO'], content)
|
108
118
|
end
|
109
119
|
logger.debug "SET Cache", began_at, @route.cache_key || env['PATH_INFO'] if defined?(logger)
|
110
120
|
end
|
@@ -35,16 +35,17 @@ module Padrino
|
|
35
35
|
def get(key)
|
36
36
|
init
|
37
37
|
if ::File.exist?(path_for_key(key))
|
38
|
-
|
38
|
+
read_method = ::File.respond_to?(:binread) ? :binread : :read
|
39
|
+
contents = ::File.send(read_method, path_for_key(key))
|
39
40
|
expires_in, body = contents.split("\n", 2)
|
40
41
|
expires_in = expires_in.to_i
|
41
42
|
if expires_in == -1 or Time.new.to_i < expires_in
|
42
43
|
Marshal.load(body) if body
|
43
|
-
else
|
44
|
+
else # expire the key
|
44
45
|
delete(key)
|
45
46
|
nil
|
46
47
|
end
|
47
|
-
else
|
48
|
+
else # key can't be found
|
48
49
|
nil
|
49
50
|
end
|
50
51
|
end
|
data/lib/padrino-cache.rb
CHANGED
@@ -91,7 +91,7 @@ module Padrino
|
|
91
91
|
app.helpers Padrino::Cache::Helpers::CacheStore
|
92
92
|
app.helpers Padrino::Cache::Helpers::Fragment
|
93
93
|
app.helpers Padrino::Cache::Helpers::Page
|
94
|
-
app.set :cache, Padrino::Cache::Store::File.new(Padrino.root('tmp', app.app_name.to_s ,'cache'))
|
94
|
+
app.set :cache, Padrino::Cache::Store::File.new(Padrino.root('tmp', defined?(app.app_name) ? app.app_name.to_s : '', 'cache'))
|
95
95
|
app.disable :caching
|
96
96
|
end
|
97
97
|
alias :included :registered
|
data/test/test_padrino_cache.rb
CHANGED
@@ -87,14 +87,14 @@ describe "PadrinoCache" do
|
|
87
87
|
get "/foo"
|
88
88
|
assert_equal 200, status
|
89
89
|
assert_equal 'foo', body
|
90
|
-
assert_equal 'foo', @app.cache.get(:foo)
|
90
|
+
assert_equal 'foo', @app.cache.get(:foo)[:response_buffer]
|
91
91
|
get "/foo"
|
92
92
|
assert_equal 'foo', body
|
93
93
|
|
94
94
|
get "/bar"
|
95
95
|
assert_equal 200, status
|
96
96
|
assert_equal 'bar', body
|
97
|
-
assert_equal 'bar', @app.cache.get(:bar)
|
97
|
+
assert_equal 'bar', @app.cache.get(:bar)[:response_buffer]
|
98
98
|
get "/bar"
|
99
99
|
assert_equal 'bar', body
|
100
100
|
end
|
metadata
CHANGED
@@ -1,8 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: padrino-cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
4
|
+
hash: 98
|
5
|
+
prerelease: 7
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 10
|
9
|
+
- 6
|
10
|
+
- a
|
11
|
+
version: 0.10.6.a
|
6
12
|
platform: ruby
|
7
13
|
authors:
|
8
14
|
- Padrino Team
|
@@ -13,8 +19,7 @@ autorequire:
|
|
13
19
|
bindir: bin
|
14
20
|
cert_chain: []
|
15
21
|
|
16
|
-
date:
|
17
|
-
default_executable:
|
22
|
+
date: 2012-01-23 00:00:00 Z
|
18
23
|
dependencies:
|
19
24
|
- !ruby/object:Gem::Dependency
|
20
25
|
name: padrino-core
|
@@ -24,7 +29,13 @@ dependencies:
|
|
24
29
|
requirements:
|
25
30
|
- - "="
|
26
31
|
- !ruby/object:Gem::Version
|
27
|
-
|
32
|
+
hash: 98
|
33
|
+
segments:
|
34
|
+
- 0
|
35
|
+
- 10
|
36
|
+
- 6
|
37
|
+
- a
|
38
|
+
version: 0.10.6.a
|
28
39
|
type: :runtime
|
29
40
|
version_requirements: *id001
|
30
41
|
description: Caching support for memcached, page and fragment
|
@@ -56,7 +67,6 @@ files:
|
|
56
67
|
- test/helper.rb
|
57
68
|
- test/test_padrino_cache.rb
|
58
69
|
- test/test_stores.rb
|
59
|
-
has_rdoc: true
|
60
70
|
homepage: http://www.padrinorb.com
|
61
71
|
licenses: []
|
62
72
|
|
@@ -70,17 +80,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
70
80
|
requirements:
|
71
81
|
- - ">="
|
72
82
|
- !ruby/object:Gem::Version
|
83
|
+
hash: 3
|
84
|
+
segments:
|
85
|
+
- 0
|
73
86
|
version: "0"
|
74
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
88
|
none: false
|
76
89
|
requirements:
|
77
|
-
- - "
|
90
|
+
- - ">"
|
78
91
|
- !ruby/object:Gem::Version
|
79
|
-
|
92
|
+
hash: 25
|
93
|
+
segments:
|
94
|
+
- 1
|
95
|
+
- 3
|
96
|
+
- 1
|
97
|
+
version: 1.3.1
|
80
98
|
requirements: []
|
81
99
|
|
82
100
|
rubyforge_project: padrino-cache
|
83
|
-
rubygems_version: 1.
|
101
|
+
rubygems_version: 1.8.15
|
84
102
|
signing_key:
|
85
103
|
specification_version: 3
|
86
104
|
summary: Page and fragment caching for Padrino
|
@@ -88,3 +106,4 @@ test_files:
|
|
88
106
|
- test/helper.rb
|
89
107
|
- test/test_padrino_cache.rb
|
90
108
|
- test/test_stores.rb
|
109
|
+
has_rdoc:
|