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.
@@ -14,15 +14,9 @@ module WillCache
14
14
 
15
15
  def cached(method_name, args = {})
16
16
  with = args[:with]
17
-
18
- # Rails.fetch is broken
19
- # http://developingsimplicity.com/posts/rails-cache-fetch
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
- key = "User:count"
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
- key = "User:1:articles"
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: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dejan Simic