will_cache 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/will_cache/cacheable.rb +4 -10
- data/test/functional/will_cache_test.rb +2 -13
- metadata +3 -3
data/lib/will_cache/cacheable.rb
CHANGED
@@ -14,15 +14,9 @@ module WillCache
|
|
14
14
|
|
15
15
|
def cached(method_name, args = {})
|
16
16
|
with = args[:with]
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
key = method_cache_key(method_name, with)
|
21
|
-
if cache.exist?(key)
|
22
|
-
cache.read(key)
|
23
|
-
else
|
24
|
-
cache.write(key, do_send(method_name, with))
|
25
|
-
end
|
17
|
+
Rails.cache.fetch(method_cache_key(method_name, with)) {
|
18
|
+
do_send(method_name, with)
|
19
|
+
}
|
26
20
|
end
|
27
21
|
alias :caches :cached
|
28
22
|
|
@@ -56,7 +50,7 @@ module WillCache
|
|
56
50
|
if with.blank?
|
57
51
|
base
|
58
52
|
else
|
59
|
-
"#{base}:#{with}
|
53
|
+
"#{base}:#{with}"
|
60
54
|
end
|
61
55
|
end
|
62
56
|
end
|
@@ -30,23 +30,12 @@ class WillCacheTest < Test::Unit::TestCase
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def test_cached_on_class_method
|
33
|
-
|
34
|
-
mock(Rails.cache).exist?(key) { false }
|
35
|
-
mock(Rails.cache).write(key, 1) { 1 }
|
33
|
+
mock(Rails.cache).fetch("User:count") { 1 }
|
36
34
|
assert_equal 1, User.cached(:count)
|
37
35
|
end
|
38
36
|
|
39
37
|
def test_cached_on_instance_method
|
40
|
-
|
41
|
-
mock(Rails.cache).exist?(key) { false }
|
42
|
-
mock(Rails.cache).write(key, @user.articles) { @user.articles }
|
43
|
-
assert_equal @user.articles, @user.cached(:articles)
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_cached_on_instance_method_on_hit
|
47
|
-
key = "User:1:articles"
|
48
|
-
mock(Rails.cache).exist?(key) { true }
|
49
|
-
mock(Rails.cache).read(key) { @user.articles }
|
38
|
+
mock(Rails.cache).fetch("User:1:articles") { @user.articles }
|
50
39
|
assert_equal @user.articles, @user.cached(:articles)
|
51
40
|
end
|
52
41
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: will_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Dejan Simic
|