julik-extremist_cache 0.0.2 → 0.0.3
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/History.txt +4 -0
- data/Rakefile +1 -0
- data/lib/extremist_cache.rb +7 -2
- data/test/test_extremist_cache.rb +12 -0
- metadata +1 -1
data/History.txt
CHANGED
data/Rakefile
CHANGED
@@ -7,6 +7,7 @@ Hoe::RUBY_FLAGS.replace ENV['RUBY_FLAGS'] || "-I#{%w(lib ext bin test).join(File
|
|
7
7
|
|
8
8
|
Hoe.new('extremist_cache', ExtremistCache::VERSION) do |p|
|
9
9
|
p.developer('Julik', 'me@julik.nl')
|
10
|
+
p.description = "Object-keyed caches for anything"
|
10
11
|
p.extra_deps << 'rails'
|
11
12
|
p.rubyforge_name = 'extremist_cache'
|
12
13
|
end
|
data/lib/extremist_cache.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'openssl'
|
2
2
|
module ExtremistCache
|
3
3
|
DIGEST = OpenSSL::Digest::MD4
|
4
|
-
VERSION = '0.0.
|
4
|
+
VERSION = '0.0.3'
|
5
5
|
|
6
6
|
# To be called from a plugin init.rb
|
7
7
|
def self.bootstrap!
|
@@ -25,7 +25,12 @@ module ExtremistCache
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def erb_cache_based_on(*whatever, &block)
|
28
|
-
|
28
|
+
begin
|
29
|
+
name = {:__extremist => lazy_cache_key_for(whatever)}
|
30
|
+
@controller.fragment_for(output_buffer, name, nil, &block)
|
31
|
+
rescue NoMethodError
|
32
|
+
@controller.cache_erb_fragment(block, lazy_cache_key_for(*whatever))
|
33
|
+
end
|
29
34
|
end
|
30
35
|
|
31
36
|
private
|
@@ -84,6 +84,11 @@ class BogusController < ActionController::Base
|
|
84
84
|
def rescue_action(e); raise e; end
|
85
85
|
def perform_expensive_computation(flag); return "wroom #{flag}"; end
|
86
86
|
def signal_return_value(retval); end
|
87
|
+
|
88
|
+
def action_that_renders_with_cache
|
89
|
+
t = '<% erb_cache_based_on(params[:id]) do %> Foo<%= params[:id] %> <%= Time.now.usec %> <% end %>'
|
90
|
+
render :inline => t
|
91
|
+
end
|
87
92
|
end
|
88
93
|
|
89
94
|
class ValueReturnTest < Test::Unit::TestCase
|
@@ -113,4 +118,11 @@ class ValueReturnTest < Test::Unit::TestCase
|
|
113
118
|
end
|
114
119
|
end
|
115
120
|
|
121
|
+
def test_cache_through_helper
|
122
|
+
get :action_that_renders_with_cache, :id => "Poeing"
|
123
|
+
first_body = @response.body.dup
|
124
|
+
|
125
|
+
10.times { get :action_that_renders_with_cache, :id => "Poeing" }
|
126
|
+
assert_equal first_body, @response.body
|
127
|
+
end
|
116
128
|
end
|