onyx-cache-money 0.2.6.1 → 0.2.6.2

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.
@@ -52,23 +52,25 @@ module Cash
52
52
  end
53
53
 
54
54
  def add(key, value, options = {})
55
- if repository.add(cache_key(key), value, options[:ttl] || 0, options[:raw]) == "NOT_STORED\r\n"
55
+ if repository.add(cache_key(key), value, options[:ttl] || cache_config.options[:ttl], options[:raw]) == "NOT_STORED\r\n"
56
56
  yield if block_given?
57
57
  end
58
58
  end
59
59
 
60
60
  def set(key, value, options = {})
61
- repository.set(cache_key(key), value, options[:ttl] || 0, options[:raw])
61
+ repository.set(cache_key(key), value, options[:ttl] || cache_config.options[:ttl], options[:raw])
62
62
  end
63
63
 
64
- def incr(key, delta = 1, ttl = 0)
64
+ def incr(key, delta = 1, ttl = nil)
65
+ ttl ||= cache_config.options[:ttl]
65
66
  repository.incr(cache_key = cache_key(key), delta) || begin
66
67
  repository.add(cache_key, (result = yield).to_s, ttl, true) { repository.incr(cache_key) }
67
68
  result
68
69
  end
69
70
  end
70
71
 
71
- def decr(key, delta = 1, ttl = 0)
72
+ def decr(key, delta = 1, ttl = nil)
73
+ ttl ||= cache_config.options[:ttl]
72
74
  repository.decr(cache_key = cache_key(key), delta) || begin
73
75
  repository.add(cache_key, (result = yield).to_s, ttl, true) { repository.decr(cache_key) }
74
76
  result
@@ -102,6 +102,11 @@ module Cash
102
102
  end
103
103
 
104
104
  describe 'when there is a cache miss' do
105
+ it 'correctly set the ttl' do
106
+ mock(Story.repository.memcache).add(Story.cache_key("count"), "2", Story.cache_config.options[:ttl], true)
107
+ Story.incr("count", 1) { 2 }
108
+ end
109
+
105
110
  it 'initializes the value of the cache to the value of the block' do
106
111
  Story.incr("count", 1) { 5 }
107
112
  Story.get("count", :raw => true).should =~ /5/
@@ -131,6 +136,20 @@ module Cash
131
136
  Story.add("count", 1)
132
137
  Story.get("count").should == 1
133
138
  end
139
+
140
+ it 'adds the key to the cache with the default ttl' do
141
+ mock(Story.repository.memcache).add(Story.cache_key("count"), 1, Story.cache_config.options[:ttl], nil)
142
+ Story.add("count", 1)
143
+ end
144
+ end
145
+ end
146
+
147
+ describe '#set' do
148
+ describe 'when the value does not already exist' do
149
+ it 'adds the key to the cache with the default ttl' do
150
+ mock(Story.repository.memcache).set(Story.cache_key("count"), 1, Story.cache_config.options[:ttl], nil)
151
+ Story.set("count", 1)
152
+ end
134
153
  end
135
154
  end
136
155
 
@@ -148,9 +167,15 @@ module Cash
148
167
  it 'returns the new cache value' do
149
168
  Story.decr("count", 2).should == 8
150
169
  end
170
+
151
171
  end
152
172
 
153
173
  describe 'when there is a cache miss' do
174
+ it 'correctly set the ttl' do
175
+ mock(Story.repository.memcache).add(Story.cache_key("count"), "2", Story.cache_config.options[:ttl], true)
176
+ Story.decr("count", 1) { 2 }
177
+ end
178
+
154
179
  it 'initializes the value of the cache to the value of the block' do
155
180
  Story.decr("count", 1) { 5 }
156
181
  Story.get("count", :raw => true).should =~ /5/
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onyx-cache-money
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6.1
4
+ version: 0.2.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Kallen
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-18 00:00:00 -07:00
12
+ date: 2009-07-08 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15