markbates-rack_page_caching 0.1.1 → 0.1.2
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.
@@ -23,7 +23,6 @@ unless ActionController.const_defined?('CONFIGURED_PAGE_CACHING_EXTENSIONS')
|
|
23
23
|
if request.get? && configatron.rack.caching.use_page_caching
|
24
24
|
cpage = Cachetastic::Caches::PageCache.get(request.url)
|
25
25
|
if cpage
|
26
|
-
response.headers['cache_this_page'] = 'false'
|
27
26
|
response.headers["Content-Type"] = cpage.content_type
|
28
27
|
render(:text => cpage.body, :layout => false)
|
29
28
|
return false
|
@@ -33,13 +32,18 @@ unless ActionController.const_defined?('CONFIGURED_PAGE_CACHING_EXTENSIONS')
|
|
33
32
|
end
|
34
33
|
|
35
34
|
def write_into_rack_page_cache
|
36
|
-
|
37
|
-
|
35
|
+
cache_control = Rack::PageCaching::Middleware.cache_controls(response.headers)
|
36
|
+
|
37
|
+
if Rack::PageCaching::Middleware.cacheable?(request, response.status.to_i, response.headers)
|
38
|
+
Rack::PageCaching::Middleware.set_into_cache(request.url,
|
39
|
+
response.body,
|
40
|
+
response.headers["Content-Type"],
|
41
|
+
cache_control[:max_age])
|
38
42
|
end
|
39
43
|
end
|
40
44
|
|
41
45
|
def set_rack_page_caching_header
|
42
|
-
|
46
|
+
expires_in configatron.cachetastic_caches_page_cache_options.default_expiry, :private => false, :public => true
|
43
47
|
end
|
44
48
|
|
45
49
|
end # Base
|
@@ -21,8 +21,9 @@ module Rack
|
|
21
21
|
ret = @app.call(env)
|
22
22
|
unless ret[2].is_a?(Rack::File)
|
23
23
|
res = ret[2]
|
24
|
-
|
25
|
-
|
24
|
+
cache_control = Rack::PageCaching::Middleware.cache_controls(res)
|
25
|
+
if Rack::PageCaching::Middleware.cacheable?(request, res.status, res)
|
26
|
+
Rack::PageCaching::Middleware.set_into_cache(request.fullpath, res.body, res["Content-Type"], cache_control[:max_age])
|
26
27
|
end
|
27
28
|
end
|
28
29
|
return ret
|
@@ -54,6 +55,33 @@ module Rack
|
|
54
55
|
|
55
56
|
end # Page
|
56
57
|
|
58
|
+
class << self
|
59
|
+
|
60
|
+
def cache_controls(headers)
|
61
|
+
cc_header = headers['Cache-Control'] || 'private'
|
62
|
+
cache_control = {:public => (!cc_header.match(/public/).nil? &&
|
63
|
+
cc_header.match(/private/).nil?),
|
64
|
+
:max_age => configatron.cachetastic_caches_page_cache_options.default_expiry}
|
65
|
+
cc_header.match(/max-age=(\d+)/)
|
66
|
+
cache_control[:max_age] = $1 unless $1.nil?
|
67
|
+
cache_control
|
68
|
+
end
|
69
|
+
|
70
|
+
def cacheable?(request, status, headers)
|
71
|
+
if configatron.rack.caching.use_page_caching
|
72
|
+
cache_control = Rack::PageCaching::Middleware.cache_controls(headers)
|
73
|
+
return cache_control[:public] && request.get? && (status.to_i >= 200 && status.to_i < 300)
|
74
|
+
end
|
75
|
+
return false
|
76
|
+
end
|
77
|
+
|
78
|
+
def set_into_cache(url, body, content_type, expiry = configatron.cachetastic_caches_page_cache_options.default_expiry)
|
79
|
+
Cachetastic::Caches::PageCache.set(url, Rack::PageCaching::Middleware::Page.new(body, content_type),
|
80
|
+
expiry.to_i)
|
81
|
+
end
|
82
|
+
|
83
|
+
end # class << self
|
84
|
+
|
57
85
|
end # Middleware
|
58
86
|
end # PageCaching
|
59
87
|
end # Rack
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: markbates-rack_page_caching
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- markbates
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-03-
|
12
|
+
date: 2009-03-16 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|