mongrel_page_cache_handler 1.6.0 → 1.6.1
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.
- data/lib/cache_server.rb +17 -5
- data/lib/cacher.rb +12 -4
- data/lib/tasks/rubyforge_config.yml +1 -1
- data/lib/utils.rb +27 -17
- metadata +7 -2
data/lib/cache_server.rb
CHANGED
@@ -5,11 +5,23 @@ module Mongrel
|
|
5
5
|
|
6
6
|
def process(request, response)
|
7
7
|
Mongrel::PageCacheHandler::Utils.do_work(request, response) do
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
case (app_config.page_cache_storage || "disk")
|
9
|
+
when "cachetastic"
|
10
|
+
file_path = Mongrel::PageCacheHandler::Utils.build_cachetastic_key(request)
|
11
|
+
f = Cachetastic::Caches::PageCache.get(file_path)
|
12
|
+
if f
|
13
|
+
puts "We found: #{file_path} in the cache, let's render it"
|
14
|
+
response.start(200, true) do |head, out|
|
15
|
+
out.write(f)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
when "disk"
|
19
|
+
file_path = Mongrel::PageCacheHandler::Utils.build_full_file_path(request)
|
20
|
+
if File.exists?(file_path)
|
21
|
+
puts "We found: #{file_path} on the disk, let's render it"
|
22
|
+
response.start(200, true) do |head, out|
|
23
|
+
out.write(File.open(file_path).read)
|
24
|
+
end
|
13
25
|
end
|
14
26
|
end
|
15
27
|
end
|
data/lib/cacher.rb
CHANGED
@@ -9,10 +9,18 @@ module Mongrel
|
|
9
9
|
sent = response.header.instance_variable_get("@sent")
|
10
10
|
mcm = sent["mongrel_cache_me"]
|
11
11
|
if mcm
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
case app_config.page_cache_storage
|
13
|
+
when "cachetastic"
|
14
|
+
# file_path = Mongrel::PageCacheHandler::Utils.build_full_file_path(request, true)
|
15
|
+
file_path = Mongrel::PageCacheHandler::Utils.build_cachetastic_key(request)
|
16
|
+
puts "Let's cache this page: #{file_path} to the cache"
|
17
|
+
Cachetastic::Caches::PageCache.set(file_path, response.body.string)
|
18
|
+
when "disk"
|
19
|
+
file_path = Mongrel::PageCacheHandler::Utils.build_full_file_path(request, true)
|
20
|
+
puts "Let's cache this page: #{file_path} to the disk"
|
21
|
+
File.open(file_path, "w") do |f|
|
22
|
+
f.puts response.body.string
|
23
|
+
end
|
16
24
|
end
|
17
25
|
end
|
18
26
|
end
|
data/lib/utils.rb
CHANGED
@@ -22,29 +22,14 @@ module Mongrel
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def build_directory_path(request, mk_dirs = false)
|
25
|
-
path = request.params[Mongrel::Const::PATH_INFO]# + ActionController::Base.page_cache_extension
|
26
|
-
if path == "/"
|
27
|
-
path = "/index"
|
28
|
-
end
|
29
25
|
pcd = ActionController::Base.page_cache_directory
|
30
|
-
dir_path = File.join(pcd,
|
26
|
+
dir_path = File.join(pcd, build_path(request))
|
31
27
|
FileUtils.mkdir_p(dir_path) if mk_dirs
|
32
28
|
dir_path
|
33
29
|
end
|
34
30
|
|
35
31
|
def build_file_name(request)
|
36
|
-
|
37
|
-
path = "/index" if path == "/"
|
38
|
-
url = path
|
39
|
-
query_string = request.params["QUERY_STRING"]
|
40
|
-
query_params = {:page => "1"}
|
41
|
-
unless query_string.blank?
|
42
|
-
query_string.split("&").sort.each do |pair|
|
43
|
-
pair_values = pair.split("=")
|
44
|
-
query_params[pair_values.first.to_sym] = URI.unescape(pair_values.last)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
query_params.delete(:gclid)
|
32
|
+
query_params = build_query_params(request)
|
48
33
|
f_name = ""
|
49
34
|
query_params.each_pair do |key, value|
|
50
35
|
f_name << key.to_s
|
@@ -57,6 +42,31 @@ module Mongrel
|
|
57
42
|
f_name.chop!
|
58
43
|
f_name
|
59
44
|
end
|
45
|
+
|
46
|
+
def build_cachetastic_key(request)
|
47
|
+
File.join(build_path(request), build_file_name(request))
|
48
|
+
end
|
49
|
+
|
50
|
+
def build_query_params(request)
|
51
|
+
query_string = request.params["QUERY_STRING"]
|
52
|
+
query_params = {:page => "1"}
|
53
|
+
unless query_string.blank?
|
54
|
+
query_string.split("&").sort.each do |pair|
|
55
|
+
pair_values = pair.split("=")
|
56
|
+
query_params[pair_values.first.to_sym] = URI.unescape(pair_values.last)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
query_params.delete(:gclid)
|
60
|
+
query_params
|
61
|
+
end
|
62
|
+
|
63
|
+
def build_path(request)
|
64
|
+
path = request.params[Mongrel::Const::PATH_INFO]# + ActionController::Base.page_cache_extension
|
65
|
+
if path == "/"
|
66
|
+
path = "/index"
|
67
|
+
end
|
68
|
+
path
|
69
|
+
end
|
60
70
|
|
61
71
|
end
|
62
72
|
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
|
|
3
3
|
specification_version: 1
|
4
4
|
name: mongrel_page_cache_handler
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.6.
|
7
|
-
date: 2007-
|
6
|
+
version: 1.6.1
|
7
|
+
date: 2007-12-21 00:00:00 -05:00
|
8
8
|
summary: mongrel_page_cache_handler
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -21,6 +21,11 @@ autorequire:
|
|
21
21
|
- m_action_controller_base
|
22
22
|
- cacher
|
23
23
|
- cache_server
|
24
|
+
- utils
|
25
|
+
- mongrel_page_cache_handler
|
26
|
+
- m_action_controller_base
|
27
|
+
- cacher
|
28
|
+
- cache_server
|
24
29
|
default_executable:
|
25
30
|
bindir: bin
|
26
31
|
has_rdoc: false
|