merb-cache 0.9.7 → 0.9.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/LICENSE +2 -2
  2. data/README +207 -143
  3. data/Rakefile +55 -10
  4. data/TODO +0 -2
  5. data/lib/merb-cache/cache.rb +84 -0
  6. data/lib/merb-cache/core_ext/enumerable.rb +9 -0
  7. data/lib/merb-cache/core_ext/hash.rb +20 -0
  8. data/lib/merb-cache/merb_ext/controller.rb +167 -0
  9. data/lib/merb-cache/stores/fundamental/abstract_store.rb +101 -0
  10. data/lib/merb-cache/stores/fundamental/file_store.rb +112 -0
  11. data/lib/merb-cache/stores/fundamental/memcached_store.rb +112 -0
  12. data/lib/merb-cache/stores/strategy/abstract_strategy_store.rb +123 -0
  13. data/lib/merb-cache/stores/strategy/action_store.rb +56 -0
  14. data/lib/merb-cache/stores/strategy/adhoc_store.rb +69 -0
  15. data/lib/merb-cache/stores/strategy/gzip_store.rb +63 -0
  16. data/lib/merb-cache/stores/strategy/page_store.rb +64 -0
  17. data/lib/merb-cache/stores/strategy/sha1_store.rb +62 -0
  18. data/lib/merb-cache.rb +8 -7
  19. data/spec/merb-cache/cache_spec.rb +88 -0
  20. data/spec/merb-cache/core_ext/enumerable_spec.rb +22 -0
  21. data/spec/merb-cache/core_ext/hash_spec.rb +20 -0
  22. data/spec/merb-cache/merb_ext/controller_spec.rb +284 -0
  23. data/spec/merb-cache/stores/fundamental/abstract_store_spec.rb +166 -0
  24. data/spec/merb-cache/stores/fundamental/file_store_spec.rb +186 -0
  25. data/spec/merb-cache/stores/fundamental/memcached_store_spec.rb +243 -0
  26. data/spec/merb-cache/stores/strategy/abstract_strategy_store_spec.rb +78 -0
  27. data/spec/merb-cache/stores/strategy/action_store_spec.rb +189 -0
  28. data/spec/merb-cache/stores/strategy/adhoc_store_spec.rb +225 -0
  29. data/spec/merb-cache/stores/strategy/gzip_store_spec.rb +51 -0
  30. data/spec/merb-cache/stores/strategy/page_store_spec.rb +111 -0
  31. data/spec/merb-cache/stores/strategy/sha1_store_spec.rb +75 -0
  32. data/spec/spec_helper.rb +69 -72
  33. metadata +42 -31
  34. data/lib/merb-cache/cache-action.rb +0 -144
  35. data/lib/merb-cache/cache-fragment.rb +0 -95
  36. data/lib/merb-cache/cache-page.rb +0 -203
  37. data/lib/merb-cache/cache-store/database-activerecord.rb +0 -88
  38. data/lib/merb-cache/cache-store/database-datamapper.rb +0 -79
  39. data/lib/merb-cache/cache-store/database-sequel.rb +0 -78
  40. data/lib/merb-cache/cache-store/database.rb +0 -144
  41. data/lib/merb-cache/cache-store/dummy.rb +0 -106
  42. data/lib/merb-cache/cache-store/file.rb +0 -194
  43. data/lib/merb-cache/cache-store/memcache.rb +0 -199
  44. data/lib/merb-cache/cache-store/memory.rb +0 -168
  45. data/lib/merb-cache/merb-cache.rb +0 -165
  46. data/lib/merb-cache/merbtasks.rb +0 -6
  47. data/spec/config/database.yml +0 -14
  48. data/spec/controller.rb +0 -101
  49. data/spec/log/merb_test.log +0 -433
  50. data/spec/merb-cache-action_spec.rb +0 -162
  51. data/spec/merb-cache-fragment_spec.rb +0 -100
  52. data/spec/merb-cache-page_spec.rb +0 -150
  53. data/spec/merb-cache_spec.rb +0 -15
  54. data/spec/views/cache_controller/action1.html.erb +0 -4
  55. data/spec/views/cache_controller/action2.html.haml +0 -4
@@ -1,100 +0,0 @@
1
- # TODO
2
- # more specs for fragment caching:
3
- # cache_get, cache_set, cached?, cache, expire
4
-
5
- describe "merb-cache-fragment" do
6
-
7
- it "should render index" do
8
- c = dispatch_to(CacheController, :index)
9
- c.body.should == "test index"
10
- end
11
-
12
- it "should cache the fragment (erb capture/concat)" do
13
- c = dispatch_to(CacheController, :action1)
14
- NOW = c.body.strip
15
- c.cache_get("key1").strip.should == NOW
16
- end
17
-
18
- it "should cache the fragment (haml capture/concat)" do
19
- c = dispatch_to(CacheController, :action2)
20
- now = c.body.strip
21
- c.cache_get("key11").strip.should == now
22
- sleep 1
23
- c = dispatch_to(CacheController, :action2)
24
- c.cache_get("key11").strip.should == now
25
- c.expire("key11")
26
- c.cache_get("key11").should be_nil
27
- end
28
-
29
- it "should use the fragment" do
30
- sleep 1
31
- c = dispatch_to(CacheController, :action1)
32
- c.body.strip.should == NOW
33
- end
34
-
35
- it "should expire the fragment" do
36
- CACHE.expire("key1")
37
- CACHE.cache_get("key1").should be_nil
38
- end
39
-
40
- it "should refresh the template" do
41
- c = dispatch_to(CacheController, :action1)
42
- c.body.strip.should_not == NOW
43
- end
44
-
45
- it "should return nil for unknown keys" do
46
- CACHE.cache_get("unknown_key").should be_nil
47
- end
48
-
49
- it "should expire matching keys" do
50
- CACHE.cache_set("test1", "test1")
51
- CACHE.cache_get("test1").should == "test1"
52
- CACHE.cache_set("test2", "test2")
53
- CACHE.cache_get("test2").should == "test2"
54
- CACHE.cache_set("test3", "test3")
55
- CACHE.cache_get("test3").should == "test3"
56
- CACHE.expire(:match => "test")
57
- CACHE.cache_get("test1").should be_nil
58
- CACHE.cache_get("test2").should be_nil
59
- CACHE.cache_get("test3").should be_nil
60
- end
61
-
62
- it "should expire entry after 3 seconds" do
63
- CACHE.cache_set("timed_key", "vanish in 3 seconds", 0.05)
64
- CACHE.cache_get("timed_key").should == "vanish in 3 seconds"
65
- sleep 3.5
66
- CACHE.cache_get("timed_key").should be_nil
67
- end
68
-
69
- it "should expire in many ways" do
70
- CACHE.cache_set("test1", "test1")
71
- CACHE.expire("test1")
72
- CACHE.cache_get("test1").should be_nil
73
-
74
- CACHE.cache_set("test2/id1", "test2")
75
- CACHE.expire(:key => "test2", :params => %w(id1))
76
- CACHE.cache_get("test2/id1").should be_nil
77
-
78
- CACHE.cache_set("test3", "test3")
79
- CACHE.expire(:key => "test3")
80
- CACHE.cache_get("test3").should be_nil
81
-
82
- CACHE.cache_set("test4/id1", "test4")
83
- CACHE.expire(:key => "test4", :params => %w(id1), :match => true)
84
- CACHE.cache_get("test4/id1/id2").should be_nil
85
- end
86
-
87
- it "should expire all keys" do
88
- CACHE.expire_all
89
- CACHE.cache_get("key1").should be_nil
90
- end
91
-
92
- it "should cache/restore ruby objects" do
93
- now = Time.now
94
- data = {:key1 => "key1", :key2 => "key2", :now => Time.now }
95
- CACHE.cache_set("key1", data)
96
- _data = CACHE.cache_get("key1")
97
- data.should == _data
98
- end
99
-
100
- end
@@ -1,150 +0,0 @@
1
- describe "merb-cache-page" do
2
-
3
- it "should cache page (action5)" do
4
- c = get("/cache_controller/action5")
5
- c.body.strip.should == "test action5"
6
- c.cached_page?("action5").should be_true
7
- end
8
-
9
- it "should expire page (action5)" do
10
- CACHE.expire_page("action5")
11
- CACHE.cached_page?("action5").should be_false
12
- end
13
-
14
- it "should cache page (action5) with full path" do
15
- c = get("/cache_controller/action5/this/is/a/test")
16
- c.cached_page?(:action => "action5", :params => %w(this is a test)).should be_true
17
- end
18
-
19
- it "should expire page (action5) with full path" do
20
- CACHE.expire_page(:action => "action5",
21
- :controller => "cache_controller",
22
- :params => %w(this is a test))
23
- CACHE.cached_page?(:key => "/cache_controller/action5/this/is/a/test").should be_false
24
- end
25
-
26
- it "should cache page (action6), use it and expire 3 seconds after" do
27
- CACHE.expire_page :match => true, :action => "action6"
28
- c = get("/cache_controller/action6")
29
- now = Time.now.to_s
30
- c.body.strip.should == now
31
- c.cached_page?("action6").should be_true
32
- sleep 1
33
- c = get("/cache_controller/action6")
34
- c.body.strip.should == now
35
- sleep 2
36
- c = get("/cache_controller/action6")
37
- c.body.strip.should == Time.now.to_s
38
- end
39
-
40
- it "should cache page with full path (action6) and expire in 3 seconds" do
41
- CACHE.expire_page "action6"
42
- CACHE.cached_page?(:action => "action6", :params => %w(path to nowhere)).should be_false
43
- c = get("/cache_controller/action6/path/to/nowhere/")
44
- now = Time.now.to_s
45
- c.body.strip.should == now
46
- c.cached_page?(:action => "action6", :params => %w(path to nowhere)).should be_true
47
- sleep 1
48
- c = get("/cache_controller/action6/path/to/nowhere")
49
- c.body.strip.should == now
50
- sleep 2
51
- c = get("/cache_controller/action6/path/to/nowhere")
52
- c.body.strip.should == Time.now.to_s
53
- end
54
-
55
- it "should expire page in many ways" do
56
- c = get("/cache_controller/action6")
57
- CACHE.expire_page("action6")
58
- CACHE.cached_page?("action6").should be_false
59
-
60
- c = get("/cache_controller/action6")
61
- CACHE.expire_page(:match => "/cache_control")
62
- CACHE.cached_page?(:action => "action6").should be_false
63
-
64
- c = get("/cache_controller/action6")
65
- CACHE.expire_page(:action => "action6")
66
- CACHE.cached_page?(:action => "action6").should be_false
67
-
68
- c = get("/cache_controller/action6/id1/id2")
69
- CACHE.expire_page(:action => "action6", :params => %w(id1 id2))
70
- CACHE.cached_page?(:action => "action6", :params => %w(id1 id2)).should be_false
71
-
72
- c = get("/cache_controller/action6/id1/id2")
73
- CACHE.expire_page(:action => "action6", :match => true)
74
- CACHE.cached_page?(:action => "action6", :params => %w(id1 id2)).should be_false
75
-
76
- c = get("/cache_controller/action6")
77
- CACHE.expire_page(:action => "action6", :controller => "cache_controller")
78
- CACHE.cached_page?(:action => "action6", :controller => "cache_controller").should be_false
79
-
80
- c = get("/cache_controller/action6/id1/id2")
81
- CACHE.expire_page(:action => "action6", :params => %w(id1), :match => true)
82
- CACHE.cached_page?(:action => "action6", :params => %w(id1 id2)).should be_false
83
-
84
- c = get("/cache_controller/action6/id1/id2")
85
- CACHE.expire_page(:action => "action6", :controller => "cache_controller", :match => true)
86
- CACHE.cached_page?(:action => "action6", :params => %w(id1 id2)).should be_false
87
-
88
- c = get("/cache_controller/action6/id1/id2")
89
- CACHE.expire_page(:action => "action6", :controller => "cache_controller", :params => %w(id1), :match => true)
90
- CACHE.cached_page?(:action => "action6", :params => %w(id1 id2)).should be_false
91
-
92
- c = get("/cache_controller/action6/id1/id2")
93
- CACHE.expire_page(:action => "action6", :controller => "cache_controller", :params => %w(id1 id2))
94
- CACHE.cached_page?(:action => "action6", :controller => "cache_controller", :params => %w(id1 id2)).should be_false
95
-
96
- c = get("/cache_controller/action6")
97
- CACHE.expire_page(:key => "/cache_controller/action6")
98
- CACHE.cached_page?(:key => "/cache_controller/action6").should be_false
99
- c = get("/cache_controller/action6/id1/id2")
100
- CACHE.expire_page(:key => "/cache_controller/action6", :params => %w(id1 id2))
101
- CACHE.cached_page?(:key => "/cache_controller/action6", :params => %w(id1 id2)).should be_false
102
-
103
- c = get("/cache_controller/action6/id1/id2")
104
- CACHE.expire_page(:key => "/cache_controller/action6/id1", :match => true)
105
- CACHE.cached_page?(:key => "/cache_controller/action6/id1/id2").should be_false
106
-
107
- c = get("/cache_controller/action6/id1/id2")
108
- CACHE.expire_page(:key => "/cache_controller/action6", :params => %w(id1), :match => true)
109
- CACHE.cached_page?(:key => "/cache_controller/action6/id1/id2").should be_false
110
- end
111
-
112
- it "should respect original content-type" do
113
- c = get("/cache_controller/action7.css")
114
- c.body.should == "CSS"
115
- c = get("/cache_controller/action7.css")
116
- c.params[:format].should == "css"
117
- c.cached_page?(:action => "action7", :extension => 'css').should be_true
118
-
119
- c = get("/cache_controller/action7.js")
120
- c.body.should == "JS"
121
- c = get("/cache_controller/action7.js")
122
- c.params[:format].should == "js"
123
- c.cached_page?(:action => "action7", :extension => 'js').should be_true
124
-
125
- c = get("/cache_controller/action7.xml")
126
- c.body.should == "XML"
127
- c = get("/cache_controller/action7.xml")
128
- c.params[:format].should == "xml"
129
- c.cached_page?(:action => "action7", :extension => 'xml').should be_true
130
-
131
- c = get("/cache_controller/action7.jpg")
132
- c.body.should == "JPG"
133
- c = get("/cache_controller/action7.jpg")
134
- c.params[:format].should == "jpg"
135
- c.cached_page?(:action => "action7", :extension => 'jpg').should be_true
136
-
137
- c = get("/cache_controller/action7.html")
138
- c.body.should == "HTML"
139
- c = get("/cache_controller/action7.html")
140
- c.params[:format].should == "html"
141
- c.cached_page?(:action => "action7").should be_true
142
- end
143
-
144
- it "should expire all pages" do
145
- CACHE.expire_all_pages
146
- CACHE.cached_page?("action6").should be_false
147
- Dir.glob(Merb::Controller._cache.config[:cache_html_directory] + '/*').should be_empty
148
- end
149
-
150
- end
@@ -1,15 +0,0 @@
1
- require File.dirname(__FILE__) + "/spec_helper"
2
-
3
- Merb::Router.prepare do |r|
4
- r.default_routes
5
- r.match("/").to(:controller => "cache_controller", :action =>"index")
6
- end
7
-
8
- CACHE = CacheController.new(Merb::Test::RequestHelper::FakeRequest.new)
9
- CACHE.expire_all
10
-
11
- puts "Using #{CACHE._cache.store.cache_store_type.inspect} store"
12
-
13
- require File.dirname(__FILE__) + "/merb-cache-fragment_spec"
14
- require File.dirname(__FILE__) + "/merb-cache-action_spec"
15
- require File.dirname(__FILE__) + "/merb-cache-page_spec"
@@ -1,4 +0,0 @@
1
- <%- cache('key1') do -%>
2
- <%= Time.now %>
3
- <%- end -%>
4
-
@@ -1,4 +0,0 @@
1
- - cache('key11') do
2
- = Time.now
3
- - end
4
-