cachetastic 1.6.0 → 1.7.0

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.
@@ -128,21 +128,27 @@
128
128
  </div>
129
129
 
130
130
  <div class="method-description">
131
+ <p>
132
+ Returns an object from the cache for a given key. If the object returned is
133
+ nil and the self_populate parameter is true then the key will be used to
134
+ try and find the object in the database, set the object into the cache, and
135
+ then return the object.
136
+ </p>
131
137
  <p><a class="source-toggle" href="#"
132
138
  onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
133
139
  <div class="method-source-code" id="M000003-source">
134
140
  <pre>
135
- <span class="ruby-comment cmt"># File lib/rails_extensions/cachetastic_active_record_base.rb, line 9</span>
136
- 9: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">get_from_cache</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">self_populate</span> = <span class="ruby-keyword kw">false</span>)
137
- 10: <span class="ruby-identifier">res</span> = <span class="ruby-identifier">cache_class</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">key</span>)
138
- 11: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">res</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">self_populate</span>
139
- 12: <span class="ruby-identifier">res</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">name</span>.<span class="ruby-identifier">constantize</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">key</span>)
140
- 13: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">res</span>.<span class="ruby-identifier">nil?</span>
141
- 14: <span class="ruby-identifier">res</span>.<span class="ruby-identifier">cache_self</span>
142
- 15: <span class="ruby-keyword kw">end</span>
143
- 16: <span class="ruby-keyword kw">end</span>
144
- 17: <span class="ruby-identifier">res</span>
145
- 18: <span class="ruby-keyword kw">end</span>
141
+ <span class="ruby-comment cmt"># File lib/rails_extensions/cachetastic_active_record_base.rb, line 13</span>
142
+ 13: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">get_from_cache</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">self_populate</span> = <span class="ruby-keyword kw">false</span>)
143
+ 14: <span class="ruby-identifier">res</span> = <span class="ruby-identifier">cache_class</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">key</span>)
144
+ 15: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">res</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">self_populate</span>
145
+ 16: <span class="ruby-identifier">res</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">name</span>.<span class="ruby-identifier">constantize</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">key</span>)
146
+ 17: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">res</span>.<span class="ruby-identifier">nil?</span>
147
+ 18: <span class="ruby-identifier">res</span>.<span class="ruby-identifier">cache_self</span>
148
+ 19: <span class="ruby-keyword kw">end</span>
149
+ 20: <span class="ruby-keyword kw">end</span>
150
+ 21: <span class="ruby-identifier">res</span>
151
+ 22: <span class="ruby-keyword kw">end</span>
146
152
  </pre>
147
153
  </div>
148
154
  </div>
@@ -79,12 +79,7 @@
79
79
  <div id="description">
80
80
  <p>
81
81
  Include this module into an <a href="../Object.html">Object</a> to achieve
82
- simplistic <a href="../Object.html">Object</a> level caching. When
83
- including this module you <b>MUST</b> create an instance level method
84
- called cachetastic_key and have it return a valid key! If you return nil
85
- from the cachetastic_key method you will not be able to use the <a
86
- href="Cacheable.html#M000047">cache_self</a> and <a
87
- href="Cacheable.html#M000048">uncache_self</a> methods.
82
+ simplistic <a href="../Object.html">Object</a> level caching.
88
83
  </p>
89
84
  <p>
90
85
  Example:
@@ -162,7 +157,7 @@ Unless the object&#8216;s cachetastic_key method returns nil this method
162
157
  will store the object in the cache using the object&#8216;s cachetastic_key
163
158
  as the key. You <b>MUST</b> create an instance level method called
164
159
  cachetastic_key and have it return a valid key! If you return nil from the
165
- cachetastic_key method you will not be able to use the <a
160
+ cachetastic_key method or you will not be able to use the <a
166
161
  href="Cacheable.html#M000047">cache_self</a> and <a
167
162
  href="Cacheable.html#M000048">uncache_self</a> methods.
168
163
  </p>
@@ -188,10 +183,10 @@ Example:
188
183
  onclick="toggleCode('M000047-source');return false;">[Source]</a></p>
189
184
  <div class="method-source-code" id="M000047-source">
190
185
  <pre>
191
- <span class="ruby-comment cmt"># File lib/cachetastic_cacheable.rb, line 143</span>
192
- 143: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">cache_self</span>
193
- 144: <span class="ruby-identifier">cache_class</span>.<span class="ruby-identifier">set</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">cachetastic_key</span>, <span class="ruby-keyword kw">self</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">cachetastic_key</span>.<span class="ruby-identifier">nil?</span>
194
- 145: <span class="ruby-keyword kw">end</span>
186
+ <span class="ruby-comment cmt"># File lib/cachetastic_cacheable.rb, line 140</span>
187
+ 140: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">cache_self</span>
188
+ 141: <span class="ruby-identifier">cache_class</span>.<span class="ruby-identifier">set</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">cachetastic_key</span>, <span class="ruby-keyword kw">self</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">cachetastic_key</span>.<span class="ruby-identifier">nil?</span>
189
+ 142: <span class="ruby-keyword kw">end</span>
195
190
  </pre>
196
191
  </div>
197
192
  </div>
@@ -212,7 +207,7 @@ Unless the object&#8216;s cachetastic_key method returns nil this method
212
207
  will delete the object in the cache using the object&#8216;s
213
208
  cachetastic_key as the key. You <b>MUST</b> create an instance level method
214
209
  called cachetastic_key and have it return a valid key! If you return nil
215
- from the cachetastic_key method you will not be able to use the <a
210
+ from the cachetastic_key method or you will not be able to use the <a
216
211
  href="Cacheable.html#M000047">cache_self</a> and <a
217
212
  href="Cacheable.html#M000048">uncache_self</a> methods.
218
213
  </p>
@@ -240,10 +235,10 @@ Example:
240
235
  onclick="toggleCode('M000048-source');return false;">[Source]</a></p>
241
236
  <div class="method-source-code" id="M000048-source">
242
237
  <pre>
243
- <span class="ruby-comment cmt"># File lib/cachetastic_cacheable.rb, line 169</span>
244
- 169: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">uncache_self</span>
245
- 170: <span class="ruby-identifier">cache_class</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">cachetastic_key</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">cachetastic_key</span>.<span class="ruby-identifier">nil?</span>
246
- 171: <span class="ruby-keyword kw">end</span>
238
+ <span class="ruby-comment cmt"># File lib/cachetastic_cacheable.rb, line 166</span>
239
+ 166: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">uncache_self</span>
240
+ 167: <span class="ruby-identifier">cache_class</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">cachetastic_key</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">cachetastic_key</span>.<span class="ruby-identifier">nil?</span>
241
+ 168: <span class="ruby-keyword kw">end</span>
247
242
  </pre>
248
243
  </div>
249
244
  </div>
@@ -139,21 +139,21 @@ Example:
139
139
  onclick="toggleCode('M000049-source');return false;">[Source]</a></p>
140
140
  <div class="method-source-code" id="M000049-source">
141
141
  <pre>
142
- <span class="ruby-comment cmt"># File lib/cachetastic_cacheable.rb, line 42</span>
143
- 42: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">cache_class</span>
144
- 43: <span class="ruby-identifier">n</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">name</span>
145
- 44: <span class="ruby-identifier">n</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">name</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">n</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;Class&quot;</span>
146
- 45: <span class="ruby-comment cmt"># puts &quot;n: #{n}&quot;</span>
147
- 46: <span class="ruby-identifier">c_name</span> = <span class="ruby-node">&quot;Cachetastic::Cacheable::#{n}Cache&quot;</span>
148
- 47: <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">Cachetastic</span><span class="ruby-operator">::</span><span class="ruby-constant">Cacheable</span>.<span class="ruby-identifier">const_defined?</span>(<span class="ruby-node">&quot;#{n}Cache&quot;</span>)
149
- 48: <span class="ruby-comment cmt"># puts &quot;we need to create a cache for: #{c_name}&quot;</span>
150
- 49: <span class="ruby-identifier">eval</span> <span class="ruby-node">%{
151
- 50: class #{c_name} &lt; Cachetastic::Caches::Base
152
- 51: end
153
- 52: }</span>
154
- 53: <span class="ruby-keyword kw">end</span>
155
- 54: <span class="ruby-identifier">c_name</span>.<span class="ruby-identifier">constantize</span>
156
- 55: <span class="ruby-keyword kw">end</span>
142
+ <span class="ruby-comment cmt"># File lib/cachetastic_cacheable.rb, line 39</span>
143
+ 39: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">cache_class</span>
144
+ 40: <span class="ruby-identifier">n</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">name</span>
145
+ 41: <span class="ruby-identifier">n</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">name</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">n</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;Class&quot;</span>
146
+ 42: <span class="ruby-comment cmt"># puts &quot;n: #{n}&quot;</span>
147
+ 43: <span class="ruby-identifier">c_name</span> = <span class="ruby-node">&quot;Cachetastic::Cacheable::#{n}Cache&quot;</span>
148
+ 44: <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">Cachetastic</span><span class="ruby-operator">::</span><span class="ruby-constant">Cacheable</span>.<span class="ruby-identifier">const_defined?</span>(<span class="ruby-node">&quot;#{n}Cache&quot;</span>)
149
+ 45: <span class="ruby-comment cmt"># puts &quot;we need to create a cache for: #{c_name}&quot;</span>
150
+ 46: <span class="ruby-identifier">eval</span> <span class="ruby-node">%{
151
+ 47: class #{c_name} &lt; Cachetastic::Caches::Base
152
+ 48: end
153
+ 49: }</span>
154
+ 50: <span class="ruby-keyword kw">end</span>
155
+ 51: <span class="ruby-identifier">c_name</span>.<span class="ruby-identifier">constantize</span>
156
+ 52: <span class="ruby-keyword kw">end</span>
157
157
  </pre>
158
158
  </div>
159
159
  </div>
@@ -192,34 +192,31 @@ Example:
192
192
  end
193
193
  end
194
194
  end
195
+
196
+ Person.new.always_the_same(1,2) # =&gt; 3
197
+ Person.new.always_the_same(2,2) # =&gt; 3
198
+ Person.new.always_the_same(3,3) # =&gt; 3
199
+ Person.cacher(&quot;always_the_same&quot;) # =&gt; 3
200
+ Person.get_from_cache(&quot;always_the_same&quot;) # =&gt; 3
201
+ Cachetastic::Cacheable::PersonCache.get(&quot;always_the_same&quot;) # =&gt; 3
202
+
203
+ Person.cacher(&quot;say_hi&quot;) {&quot;Hi There&quot;} # =&gt; &quot;Hi There&quot;
204
+ Person.get_from_cache(&quot;say_hi&quot;) # =&gt; &quot;Hi There&quot;
205
+ Cachetastic::Cacheable::PersonCache.get(&quot;say_hi&quot;) # =&gt; &quot;Hi There&quot;
195
206
  </pre>
196
- <p>
197
- Person.new.always_the_same(1,2) # =&gt; 3 Person.new.always_the_same(2,2) #
198
- =&gt; 3 Person.new.always_the_same(3,3) # =&gt; 3
199
- Person.cacher(&quot;always_the_same&quot;) # =&gt; 3
200
- Person.get_from_cache(&quot;always_the_same&quot;) # =&gt; 3
201
- Cachetastic::Cacheable::PersonCache.get(&quot;always_the_same&quot;) #
202
- =&gt; 3
203
- </p>
204
- <p>
205
- Person.cacher(&quot;say_hi&quot;) {&quot;Hi There&quot;} # =&gt; &quot;Hi
206
- There&quot; Person.get_from_cache(&quot;say_hi&quot;) # =&gt; &quot;Hi
207
- There&quot; Cachetastic::Cacheable::PersonCache.get(&quot;say_hi&quot;) #
208
- =&gt; &quot;Hi There&quot;
209
- </p>
210
207
  <p><a class="source-toggle" href="#"
211
208
  onclick="toggleCode('M000050-source');return false;">[Source]</a></p>
212
209
  <div class="method-source-code" id="M000050-source">
213
210
  <pre>
214
- <span class="ruby-comment cmt"># File lib/cachetastic_cacheable.rb, line 87</span>
215
- 87: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">cacher</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">expiry</span> = <span class="ruby-value">0</span>)
216
- 88: <span class="ruby-identifier">cache_class</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">key</span>) <span class="ruby-keyword kw">do</span>
217
- 89: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
218
- 90: <span class="ruby-identifier">res</span> = <span class="ruby-keyword kw">yield</span>
219
- 91: <span class="ruby-identifier">cache_class</span>.<span class="ruby-identifier">set</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">res</span>, <span class="ruby-identifier">expiry</span>)
220
- 92: <span class="ruby-keyword kw">end</span>
221
- 93: <span class="ruby-keyword kw">end</span>
222
- 94: <span class="ruby-keyword kw">end</span>
211
+ <span class="ruby-comment cmt"># File lib/cachetastic_cacheable.rb, line 84</span>
212
+ 84: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">cacher</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">expiry</span> = <span class="ruby-value">0</span>)
213
+ 85: <span class="ruby-identifier">cache_class</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">key</span>) <span class="ruby-keyword kw">do</span>
214
+ 86: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
215
+ 87: <span class="ruby-identifier">res</span> = <span class="ruby-keyword kw">yield</span>
216
+ 88: <span class="ruby-identifier">cache_class</span>.<span class="ruby-identifier">set</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">res</span>, <span class="ruby-identifier">expiry</span>)
217
+ 89: <span class="ruby-keyword kw">end</span>
218
+ 90: <span class="ruby-keyword kw">end</span>
219
+ 91: <span class="ruby-keyword kw">end</span>
223
220
  </pre>
224
221
  </div>
225
222
  </div>
@@ -263,10 +260,10 @@ Example:
263
260
  onclick="toggleCode('M000051-source');return false;">[Source]</a></p>
264
261
  <div class="method-source-code" id="M000051-source">
265
262
  <pre>
266
- <span class="ruby-comment cmt"># File lib/cachetastic_cacheable.rb, line 115</span>
267
- 115: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">expire_all</span>
268
- 116: <span class="ruby-identifier">cache_class</span>.<span class="ruby-identifier">expire_all</span>
269
- 117: <span class="ruby-keyword kw">end</span>
263
+ <span class="ruby-comment cmt"># File lib/cachetastic_cacheable.rb, line 112</span>
264
+ 112: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">expire_all</span>
265
+ 113: <span class="ruby-identifier">cache_class</span>.<span class="ruby-identifier">expire_all</span>
266
+ 114: <span class="ruby-keyword kw">end</span>
270
267
  </pre>
271
268
  </div>
272
269
  </div>
@@ -121,10 +121,10 @@ Deletes an object from the cache for a given key.
121
121
  onclick="toggleCode('M000053-source');return false;">[Source]</a></p>
122
122
  <div class="method-source-code" id="M000053-source">
123
123
  <pre>
124
- <span class="ruby-comment cmt"># File lib/cachetastic_cacheable.rb, line 191</span>
125
- 191: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">delete_from_cache</span>(<span class="ruby-identifier">key</span>)
126
- 192: <span class="ruby-identifier">cache_class</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">key</span>)
127
- 193: <span class="ruby-keyword kw">end</span>
124
+ <span class="ruby-comment cmt"># File lib/cachetastic_cacheable.rb, line 185</span>
125
+ 185: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">delete_from_cache</span>(<span class="ruby-identifier">key</span>)
126
+ 186: <span class="ruby-identifier">cache_class</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">key</span>)
127
+ 187: <span class="ruby-keyword kw">end</span>
128
128
  </pre>
129
129
  </div>
130
130
  </div>
@@ -141,19 +141,16 @@ Deletes an object from the cache for a given key.
141
141
 
142
142
  <div class="method-description">
143
143
  <p>
144
- Returns an object from the cache for a given key. If the object returned is
145
- nil and the self_populate parameter is true then the key will be used to
146
- try and find the object in the database, set the object into the cache, and
147
- then return the object.
144
+ Returns an object from the cache for a given key.
148
145
  </p>
149
146
  <p><a class="source-toggle" href="#"
150
147
  onclick="toggleCode('M000052-source');return false;">[Source]</a></p>
151
148
  <div class="method-source-code" id="M000052-source">
152
149
  <pre>
153
- <span class="ruby-comment cmt"># File lib/cachetastic_cacheable.rb, line 186</span>
154
- 186: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">get_from_cache</span>(<span class="ruby-identifier">key</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
155
- 187: <span class="ruby-identifier">cache_class</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">key</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
156
- 188: <span class="ruby-keyword kw">end</span>
150
+ <span class="ruby-comment cmt"># File lib/cachetastic_cacheable.rb, line 180</span>
151
+ 180: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">get_from_cache</span>(<span class="ruby-identifier">key</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
152
+ 181: <span class="ruby-identifier">cache_class</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">key</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
153
+ 182: <span class="ruby-keyword kw">end</span>
157
154
  </pre>
158
155
  </div>
159
156
  </div>
@@ -176,10 +173,10 @@ Sets an object into the cache for a given key.
176
173
  onclick="toggleCode('M000054-source');return false;">[Source]</a></p>
177
174
  <div class="method-source-code" id="M000054-source">
178
175
  <pre>
179
- <span class="ruby-comment cmt"># File lib/cachetastic_cacheable.rb, line 196</span>
180
- 196: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">set_into_cache</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span>, <span class="ruby-identifier">expiry</span> = <span class="ruby-value">0</span>)
181
- 197: <span class="ruby-identifier">cache_class</span>.<span class="ruby-identifier">set</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span>, <span class="ruby-identifier">expiry</span>)
182
- 198: <span class="ruby-keyword kw">end</span>
176
+ <span class="ruby-comment cmt"># File lib/cachetastic_cacheable.rb, line 190</span>
177
+ 190: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">set_into_cache</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span>, <span class="ruby-identifier">expiry</span> = <span class="ruby-value">0</span>)
178
+ 191: <span class="ruby-identifier">cache_class</span>.<span class="ruby-identifier">set</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span>, <span class="ruby-identifier">expiry</span>)
179
+ 192: <span class="ruby-keyword kw">end</span>
183
180
  </pre>
184
181
  </div>
185
182
  </div>
@@ -373,7 +373,7 @@ results of the block are not automatically cached.
373
373
  <div class="method-source-code" id="M000057-source">
374
374
  <pre>
375
375
  <span class="ruby-comment cmt"># File lib/caches/cachetastic_caches_base.rb, line 58</span>
376
- 58: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">get</span>(<span class="ruby-identifier">key</span>)
376
+ 58: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">get</span>(<span class="ruby-identifier">key</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
377
377
  59: <span class="ruby-identifier">res</span> = <span class="ruby-keyword kw">nil</span>
378
378
  60: <span class="ruby-identifier">do_with_logging</span>(<span class="ruby-identifier">:get</span>, <span class="ruby-identifier">key</span>) <span class="ruby-keyword kw">do</span>
379
379
  61: <span class="ruby-identifier">retryable</span>(<span class="ruby-identifier">:on</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">ArgumentError</span>) <span class="ruby-keyword kw">do</span>
data/doc/created.rid CHANGED
@@ -1 +1 @@
1
- Tue, 03 Jun 2008 17:30:28 -0400
1
+ Wed, 04 Jun 2008 10:11:52 -0400
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Tue Jun 03 13:14:49 -0400 2008</td>
59
+ <td>Wed Jun 04 10:11:36 -0400 2008</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Tue Jun 03 17:28:04 -0400 2008</td>
59
+ <td>Wed Jun 04 10:11:36 -0400 2008</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Tue Jun 03 16:59:08 -0400 2008</td>
59
+ <td>Wed Jun 04 10:11:36 -0400 2008</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -186,6 +186,7 @@ The server takes to command line parameters: -h &lt;host&gt; -p
186
186
  zlib&nbsp;&nbsp;
187
187
  pp&nbsp;&nbsp;
188
188
  drb&nbsp;&nbsp;
189
+ mack_ruby_core_extensions&nbsp;&nbsp;
189
190
  application_configuration&nbsp;&nbsp;
190
191
  memcache&nbsp;&nbsp;
191
192
  </div>
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Tue Jun 03 17:25:57 -0400 2008</td>
59
+ <td>Wed Jun 04 10:11:36 -0400 2008</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -55,7 +55,7 @@ class Cachetastic::Caches::Base
55
55
  # will be run. This can be used to JIT caches, just make
56
56
  # sure in the block to call the set method because the
57
57
  # results of the block are not automatically cached.
58
- def get(key)
58
+ def get(key, &block)
59
59
  res = nil
60
60
  do_with_logging(:get, key) do
61
61
  retryable(:on => ArgumentError) do
data/lib/cachetastic.rb CHANGED
@@ -6,6 +6,7 @@ require 'yaml'
6
6
  require 'zlib'
7
7
  require 'pp'
8
8
  require 'drb'
9
+ require 'mack_ruby_core_extensions'
9
10
  require 'application_configuration'
10
11
  begin
11
12
  require 'memcache'
@@ -13,7 +14,7 @@ rescue Exception => e
13
14
  # if you don't have memcache installed, don't
14
15
  # blow up, print a message, and you can't use
15
16
  # the memcache adapter.
16
- puts e.message
17
+ puts "Warning: You don't have the memcache gem installed which means you can't use the Cachetastic::Adapters::Memcache adapter."
17
18
  end
18
19
 
19
20
 
@@ -1,8 +1,5 @@
1
1
  module Cachetastic
2
2
  # Include this module into an Object to achieve simplistic Object level caching.
3
- # When including this module you *MUST* create an instance level method called cachetastic_key and
4
- # have it return a valid key! If you return nil from the cachetastic_key method you will not be
5
- # able to use the cache_self and uncache_self methods.
6
3
  #
7
4
  # Example:
8
5
  # class Person
@@ -74,16 +71,16 @@ module Cachetastic
74
71
  # end
75
72
  # end
76
73
  #
77
- # Person.new.always_the_same(1,2) # => 3
78
- # Person.new.always_the_same(2,2) # => 3
79
- # Person.new.always_the_same(3,3) # => 3
80
- # Person.cacher("always_the_same") # => 3
81
- # Person.get_from_cache("always_the_same") # => 3
82
- # Cachetastic::Cacheable::PersonCache.get("always_the_same") # => 3
83
- #
84
- # Person.cacher("say_hi") {"Hi There"} # => "Hi There"
85
- # Person.get_from_cache("say_hi") # => "Hi There"
86
- # Cachetastic::Cacheable::PersonCache.get("say_hi") # => "Hi There"
74
+ # Person.new.always_the_same(1,2) # => 3
75
+ # Person.new.always_the_same(2,2) # => 3
76
+ # Person.new.always_the_same(3,3) # => 3
77
+ # Person.cacher("always_the_same") # => 3
78
+ # Person.get_from_cache("always_the_same") # => 3
79
+ # Cachetastic::Cacheable::PersonCache.get("always_the_same") # => 3
80
+ #
81
+ # Person.cacher("say_hi") {"Hi There"} # => "Hi There"
82
+ # Person.get_from_cache("say_hi") # => "Hi There"
83
+ # Cachetastic::Cacheable::PersonCache.get("say_hi") # => "Hi There"
87
84
  def cacher(key, expiry = 0)
88
85
  cache_class.get(key) do
89
86
  if block_given?
@@ -123,7 +120,7 @@ module Cachetastic
123
120
  # Unless the object's cachetastic_key method returns nil this method will store
124
121
  # the object in the cache using the object's cachetastic_key as the key.
125
122
  # You *MUST* create an instance level method called cachetastic_key and
126
- # have it return a valid key! If you return nil from the cachetastic_key method you will not be
123
+ # have it return a valid key! If you return nil from the cachetastic_key method or you will not be
127
124
  # able to use the cache_self and uncache_self methods.
128
125
  #
129
126
  # Example:
@@ -147,7 +144,7 @@ module Cachetastic
147
144
  # Unless the object's cachetastic_key method returns nil this method will delete
148
145
  # the object in the cache using the object's cachetastic_key as the key.
149
146
  # You *MUST* create an instance level method called cachetastic_key and
150
- # have it return a valid key! If you return nil from the cachetastic_key method you will not be
147
+ # have it return a valid key! If you return nil from the cachetastic_key method or you will not be
151
148
  # able to use the cache_self and uncache_self methods.
152
149
  #
153
150
  # Example:
@@ -180,9 +177,6 @@ module Cachetastic
180
177
 
181
178
  module ClassOnlyMethods
182
179
  # Returns an object from the cache for a given key.
183
- # If the object returned is nil and the self_populate parameter is true
184
- # then the key will be used to try and find the object in the database,
185
- # set the object into the cache, and then return the object.
186
180
  def get_from_cache(key, &block)
187
181
  cache_class.get(key, &block)
188
182
  end
@@ -6,6 +6,10 @@ class ActiveRecord::Base
6
6
  self.id
7
7
  end
8
8
 
9
+ # Returns an object from the cache for a given key.
10
+ # If the object returned is nil and the self_populate parameter is true
11
+ # then the key will be used to try and find the object in the database,
12
+ # set the object into the cache, and then return the object.
9
13
  def self.get_from_cache(key, self_populate = false)
10
14
  res = cache_class.get(key)
11
15
  if res.nil? && self_populate
@@ -67,6 +67,10 @@ class CacheableTest < Test::Unit::TestCase
67
67
  def test_get_from_cache
68
68
  assert_nil Person.get_from_cache("i should be nil")
69
69
  assert_equal 86, Person.get_from_cache("maxwell smart") {86}
70
+ x = Person.get_from_cache("my name") do |key|
71
+ "Mark Bates"
72
+ end
73
+ assert_equal "Mark Bates", x
70
74
  end
71
75
 
72
76
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cachetastic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - markbates
8
- autorequire: cachetastic
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-06-03 00:00:00 -04:00
12
+ date: 2008-06-04 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -36,8 +36,8 @@ executables: []
36
36
 
37
37
  extensions: []
38
38
 
39
- extra_rdoc_files: []
40
-
39
+ extra_rdoc_files:
40
+ - README
41
41
  files:
42
42
  - lib/adapters/cachetastic_adapters_base.rb
43
43
  - lib/adapters/cachetastic_adapters_drb.rb
@@ -108,7 +108,7 @@ files:
108
108
  - doc/fr_method_index.html
109
109
  - doc/index.html
110
110
  - doc/rdoc-style.css
111
- has_rdoc: false
111
+ has_rdoc: true
112
112
  homepage: http://www.mackframework.com
113
113
  post_install_message:
114
114
  rdoc_options: []
@@ -130,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
130
  version:
131
131
  requirements: []
132
132
 
133
- rubyforge_project:
133
+ rubyforge_project: magrathea
134
134
  rubygems_version: 1.1.1
135
135
  signing_key:
136
136
  specification_version: 2