frivol 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.5
1
+ 0.1.6
@@ -84,10 +84,11 @@
84
84
  <h3 class="section-bar">Methods</h3>
85
85
 
86
86
  <div class="name-list">
87
+ <a href="#M000006">clear_storage</a>&nbsp;&nbsp;
87
88
  <a href="#M000005">delete_storage</a>&nbsp;&nbsp;
88
- <a href="#M000006">expire_storage</a>&nbsp;&nbsp;
89
+ <a href="#M000007">expire_storage</a>&nbsp;&nbsp;
89
90
  <a href="#M000004">retrieve</a>&nbsp;&nbsp;
90
- <a href="#M000007">storage_key</a>&nbsp;&nbsp;
91
+ <a href="#M000008">storage_key</a>&nbsp;&nbsp;
91
92
  <a href="#M000003">store</a>&nbsp;&nbsp;
92
93
  </div>
93
94
  </div>
@@ -135,6 +136,24 @@ Defines a constant to indicate that storage should never expire
135
136
  <div id="methods">
136
137
  <h3 class="section-bar">Public Instance methods</h3>
137
138
 
139
+ <div id="method-M000006" class="method-detail">
140
+ <a name="M000006"></a>
141
+
142
+ <div class="method-heading">
143
+ <a href="Frivol.src/M000006.html" target="Code" class="method-signature"
144
+ onclick="popupCode('Frivol.src/M000006.html');return false;">
145
+ <span class="method-name">clear_storage</span><span class="method-args">()</span>
146
+ </a>
147
+ </div>
148
+
149
+ <div class="method-description">
150
+ <p>
151
+ Clears the cached values and forces the next <a
152
+ href="Frivol.html#M000004">retrieve</a> to fetch from Redis.
153
+ </p>
154
+ </div>
155
+ </div>
156
+
138
157
  <div id="method-M000005" class="method-detail">
139
158
  <a name="M000005"></a>
140
159
 
@@ -147,17 +166,17 @@ Defines a constant to indicate that storage should never expire
147
166
 
148
167
  <div class="method-description">
149
168
  <p>
150
- Deletes the stored values.
169
+ Deletes the stored values (and clears the cache).
151
170
  </p>
152
171
  </div>
153
172
  </div>
154
173
 
155
- <div id="method-M000006" class="method-detail">
156
- <a name="M000006"></a>
174
+ <div id="method-M000007" class="method-detail">
175
+ <a name="M000007"></a>
157
176
 
158
177
  <div class="method-heading">
159
- <a href="Frivol.src/M000006.html" target="Code" class="method-signature"
160
- onclick="popupCode('Frivol.src/M000006.html');return false;">
178
+ <a href="Frivol.src/M000007.html" target="Code" class="method-signature"
179
+ onclick="popupCode('Frivol.src/M000007.html');return false;">
161
180
  <span class="method-name">expire_storage</span><span class="method-args">(time, bucket = nil)</span>
162
181
  </a>
163
182
  </div>
@@ -201,12 +220,12 @@ be the default.
201
220
  </div>
202
221
  </div>
203
222
 
204
- <div id="method-M000007" class="method-detail">
205
- <a name="M000007"></a>
223
+ <div id="method-M000008" class="method-detail">
224
+ <a name="M000008"></a>
206
225
 
207
226
  <div class="method-heading">
208
- <a href="Frivol.src/M000007.html" target="Code" class="method-signature"
209
- onclick="popupCode('Frivol.src/M000007.html');return false;">
227
+ <a href="Frivol.src/M000008.html" target="Code" class="method-signature"
228
+ onclick="popupCode('Frivol.src/M000008.html');return false;">
210
229
  <span class="method-name">storage_key</span><span class="method-args">(bucket = nil)</span>
211
230
  </a>
212
231
  </div>
@@ -10,7 +10,7 @@
10
10
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
11
  </head>
12
12
  <body class="standalone-code">
13
- <pre><span class="ruby-comment cmt"># File lib/frivol.rb, line 97</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/frivol.rb, line 98</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">store</span>(<span class="ruby-identifier">keys_and_values</span>)
15
15
  <span class="ruby-identifier">hash</span> = <span class="ruby-constant">Frivol</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>.<span class="ruby-identifier">retrieve_hash</span>(<span class="ruby-keyword kw">self</span>)
16
16
  <span class="ruby-identifier">keys_and_values</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
@@ -10,7 +10,7 @@
10
10
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
11
  </head>
12
12
  <body class="standalone-code">
13
- <pre><span class="ruby-comment cmt"># File lib/frivol.rb, line 114</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/frivol.rb, line 115</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">retrieve</span>(<span class="ruby-identifier">keys_and_defaults</span>)
15
15
  <span class="ruby-identifier">hash</span> = <span class="ruby-constant">Frivol</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>.<span class="ruby-identifier">retrieve_hash</span>(<span class="ruby-keyword kw">self</span>)
16
16
  <span class="ruby-identifier">result</span> = <span class="ruby-identifier">keys_and_defaults</span>.<span class="ruby-identifier">map</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">default</span><span class="ruby-operator">|</span>
@@ -10,7 +10,7 @@
10
10
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
11
  </head>
12
12
  <body class="standalone-code">
13
- <pre><span class="ruby-comment cmt"># File lib/frivol.rb, line 124</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/frivol.rb, line 125</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">delete_storage</span>
15
15
  <span class="ruby-constant">Frivol</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>.<span class="ruby-identifier">delete_hash</span> <span class="ruby-keyword kw">self</span>
16
16
  <span class="ruby-keyword kw">end</span></pre>
@@ -5,15 +5,14 @@
5
5
 
6
6
  <html>
7
7
  <head>
8
- <title>expire_storage (Frivol)</title>
8
+ <title>clear_storage (Frivol)</title>
9
9
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
10
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
11
  </head>
12
12
  <body class="standalone-code">
13
- <pre><span class="ruby-comment cmt"># File lib/frivol.rb, line 129</span>
14
- <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">expire_storage</span>(<span class="ruby-identifier">time</span>, <span class="ruby-identifier">bucket</span> = <span class="ruby-keyword kw">nil</span>)
15
- <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">time</span>.<span class="ruby-identifier">nil?</span>
16
- <span class="ruby-constant">Frivol</span><span class="ruby-operator">::</span><span class="ruby-constant">Config</span>.<span class="ruby-identifier">redis</span>.<span class="ruby-identifier">expire</span> <span class="ruby-identifier">storage_key</span>(<span class="ruby-identifier">bucket</span>), <span class="ruby-identifier">time</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/frivol.rb, line 130</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">clear_storage</span>
15
+ <span class="ruby-constant">Frivol</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>.<span class="ruby-identifier">clear_hash</span> <span class="ruby-keyword kw">self</span>
17
16
  <span class="ruby-keyword kw">end</span></pre>
18
17
  </body>
19
18
  </html>
@@ -5,15 +5,15 @@
5
5
 
6
6
  <html>
7
7
  <head>
8
- <title>storage_key (Frivol)</title>
8
+ <title>expire_storage (Frivol)</title>
9
9
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
10
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
11
  </head>
12
12
  <body class="standalone-code">
13
- <pre><span class="ruby-comment cmt"># File lib/frivol.rb, line 142</span>
14
- <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">storage_key</span>(<span class="ruby-identifier">bucket</span> = <span class="ruby-keyword kw">nil</span>)
15
- <span class="ruby-ivar">@frivol_key</span> <span class="ruby-operator">||=</span> <span class="ruby-node">&quot;#{self.class.name}-#{id}&quot;</span>
16
- <span class="ruby-identifier">bucket</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-value">? </span><span class="ruby-ivar">@frivol_key</span> <span class="ruby-operator">:</span> <span class="ruby-node">&quot;#{@frivol_key}-#{bucket}&quot;</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/frivol.rb, line 135</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">expire_storage</span>(<span class="ruby-identifier">time</span>, <span class="ruby-identifier">bucket</span> = <span class="ruby-keyword kw">nil</span>)
15
+ <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">time</span>.<span class="ruby-identifier">nil?</span>
16
+ <span class="ruby-constant">Frivol</span><span class="ruby-operator">::</span><span class="ruby-constant">Config</span>.<span class="ruby-identifier">redis</span>.<span class="ruby-identifier">expire</span> <span class="ruby-identifier">storage_key</span>(<span class="ruby-identifier">bucket</span>), <span class="ruby-identifier">time</span>
17
17
  <span class="ruby-keyword kw">end</span></pre>
18
18
  </body>
19
19
  </html>
@@ -0,0 +1,19 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>storage_key (Frivol)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/frivol.rb, line 148</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">storage_key</span>(<span class="ruby-identifier">bucket</span> = <span class="ruby-keyword kw">nil</span>)
15
+ <span class="ruby-ivar">@frivol_key</span> <span class="ruby-operator">||=</span> <span class="ruby-node">&quot;#{self.class.name}-#{id}&quot;</span>
16
+ <span class="ruby-identifier">bucket</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-value">? </span><span class="ruby-ivar">@frivol_key</span> <span class="ruby-operator">:</span> <span class="ruby-node">&quot;#{@frivol_key}-#{bucket}&quot;</span>
17
+ <span class="ruby-keyword kw">end</span></pre>
18
+ </body>
19
+ </html>
@@ -88,9 +88,9 @@ href="../Frivol.html">Frivol</a> is included in the class.
88
88
  <h3 class="section-bar">Methods</h3>
89
89
 
90
90
  <div class="name-list">
91
- <a href="#M000010">storage_bucket</a>&nbsp;&nbsp;
92
- <a href="#M000008">storage_expires_in</a>&nbsp;&nbsp;
93
- <a href="#M000009">storage_expiry</a>&nbsp;&nbsp;
91
+ <a href="#M000011">storage_bucket</a>&nbsp;&nbsp;
92
+ <a href="#M000009">storage_expires_in</a>&nbsp;&nbsp;
93
+ <a href="#M000010">storage_expiry</a>&nbsp;&nbsp;
94
94
  </div>
95
95
  </div>
96
96
 
@@ -112,12 +112,12 @@ href="../Frivol.html">Frivol</a> is included in the class.
112
112
  <div id="methods">
113
113
  <h3 class="section-bar">Public Instance methods</h3>
114
114
 
115
- <div id="method-M000010" class="method-detail">
116
- <a name="M000010"></a>
115
+ <div id="method-M000011" class="method-detail">
116
+ <a name="M000011"></a>
117
117
 
118
118
  <div class="method-heading">
119
- <a href="ClassMethods.src/M000010.html" target="Code" class="method-signature"
120
- onclick="popupCode('ClassMethods.src/M000010.html');return false;">
119
+ <a href="ClassMethods.src/M000011.html" target="Code" class="method-signature"
120
+ onclick="popupCode('ClassMethods.src/M000011.html');return false;">
121
121
  <span class="method-name">storage_bucket</span><span class="method-args">(bucket, options = {})</span>
122
122
  </a>
123
123
  </div>
@@ -163,12 +163,12 @@ Options are :expires_in which sets the expiry time for a bucket, and
163
163
  </div>
164
164
  </div>
165
165
 
166
- <div id="method-M000008" class="method-detail">
167
- <a name="M000008"></a>
166
+ <div id="method-M000009" class="method-detail">
167
+ <a name="M000009"></a>
168
168
 
169
169
  <div class="method-heading">
170
- <a href="ClassMethods.src/M000008.html" target="Code" class="method-signature"
171
- onclick="popupCode('ClassMethods.src/M000008.html');return false;">
170
+ <a href="ClassMethods.src/M000009.html" target="Code" class="method-signature"
171
+ onclick="popupCode('ClassMethods.src/M000009.html');return false;">
172
172
  <span class="method-name">storage_expires_in</span><span class="method-args">(time, bucket = nil)</span>
173
173
  </a>
174
174
  </div>
@@ -181,12 +181,12 @@ passed.
181
181
  </div>
182
182
  </div>
183
183
 
184
- <div id="method-M000009" class="method-detail">
185
- <a name="M000009"></a>
184
+ <div id="method-M000010" class="method-detail">
185
+ <a name="M000010"></a>
186
186
 
187
187
  <div class="method-heading">
188
- <a href="ClassMethods.src/M000009.html" target="Code" class="method-signature"
189
- onclick="popupCode('ClassMethods.src/M000009.html');return false;">
188
+ <a href="ClassMethods.src/M000010.html" target="Code" class="method-signature"
189
+ onclick="popupCode('ClassMethods.src/M000010.html');return false;">
190
190
  <span class="method-name">storage_expiry</span><span class="method-args">(bucket = nil)</span>
191
191
  </a>
192
192
  </div>
@@ -5,15 +5,15 @@
5
5
 
6
6
  <html>
7
7
  <head>
8
- <title>storage_expiry (Frivol::ClassMethods)</title>
8
+ <title>storage_expires_in (Frivol::ClassMethods)</title>
9
9
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
10
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
11
  </head>
12
12
  <body class="standalone-code">
13
- <pre><span class="ruby-comment cmt"># File lib/frivol.rb, line 252</span>
14
- <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">storage_expiry</span>(<span class="ruby-identifier">bucket</span> = <span class="ruby-keyword kw">nil</span>)
13
+ <pre><span class="ruby-comment cmt"># File lib/frivol.rb, line 262</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">storage_expires_in</span>(<span class="ruby-identifier">time</span>, <span class="ruby-identifier">bucket</span> = <span class="ruby-keyword kw">nil</span>)
15
15
  <span class="ruby-ivar">@frivol_storage_expiry</span> <span class="ruby-operator">||=</span> {}
16
- <span class="ruby-ivar">@frivol_storage_expiry</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-identifier">bucket</span>.<span class="ruby-identifier">to_s</span>) <span class="ruby-operator">?</span> <span class="ruby-ivar">@frivol_storage_expiry</span>[<span class="ruby-identifier">bucket</span>.<span class="ruby-identifier">to_s</span>] <span class="ruby-operator">:</span> <span class="ruby-constant">NEVER_EXPIRE</span>
16
+ <span class="ruby-ivar">@frivol_storage_expiry</span>[<span class="ruby-identifier">bucket</span>.<span class="ruby-identifier">to_s</span>] = <span class="ruby-identifier">time</span>
17
17
  <span class="ruby-keyword kw">end</span></pre>
18
18
  </body>
19
19
  </html>
@@ -5,49 +5,15 @@
5
5
 
6
6
  <html>
7
7
  <head>
8
- <title>storage_bucket (Frivol::ClassMethods)</title>
8
+ <title>storage_expiry (Frivol::ClassMethods)</title>
9
9
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
10
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
11
  </head>
12
12
  <body class="standalone-code">
13
- <pre><span class="ruby-comment cmt"># File lib/frivol.rb, line 276</span>
14
- <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">storage_bucket</span>(<span class="ruby-identifier">bucket</span>, <span class="ruby-identifier">options</span> = {})
15
- <span class="ruby-identifier">time</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:expires_in</span>]
16
- <span class="ruby-identifier">storage_expires_in</span>(<span class="ruby-identifier">time</span>, <span class="ruby-identifier">bucket</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">time</span>.<span class="ruby-identifier">nil?</span>
17
- <span class="ruby-identifier">is_counter</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:counter</span>]
18
-
19
- <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class_eval</span> <span class="ruby-keyword kw">do</span>
20
- <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">is_counter</span>
21
- <span class="ruby-identifier">define_method</span> <span class="ruby-node">&quot;store_#{bucket}&quot;</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
22
- <span class="ruby-constant">Frivol</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>.<span class="ruby-identifier">store_counter</span>(<span class="ruby-keyword kw">self</span>, <span class="ruby-identifier">bucket</span>, <span class="ruby-identifier">value</span>)
23
- <span class="ruby-keyword kw">end</span>
24
-
25
- <span class="ruby-identifier">define_method</span> <span class="ruby-node">&quot;retrieve_#{bucket}&quot;</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">default</span><span class="ruby-operator">|</span>
26
- <span class="ruby-constant">Frivol</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>.<span class="ruby-identifier">retrieve_counter</span>(<span class="ruby-keyword kw">self</span>, <span class="ruby-identifier">bucket</span>, <span class="ruby-identifier">default</span>)
27
- <span class="ruby-keyword kw">end</span>
28
-
29
- <span class="ruby-identifier">define_method</span> <span class="ruby-node">&quot;increment_#{bucket}&quot;</span> <span class="ruby-keyword kw">do</span>
30
- <span class="ruby-constant">Frivol</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>.<span class="ruby-identifier">increment_counter</span>(<span class="ruby-keyword kw">self</span>, <span class="ruby-identifier">bucket</span>)
31
- <span class="ruby-keyword kw">end</span>
32
- <span class="ruby-keyword kw">else</span>
33
- <span class="ruby-identifier">define_method</span> <span class="ruby-node">&quot;store_#{bucket}&quot;</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">keys_and_values</span><span class="ruby-operator">|</span>
34
- <span class="ruby-identifier">hash</span> = <span class="ruby-constant">Frivol</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>.<span class="ruby-identifier">retrieve_hash</span>(<span class="ruby-keyword kw">self</span>, <span class="ruby-identifier">bucket</span>)
35
- <span class="ruby-identifier">keys_and_values</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
36
- <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_s</span>] = <span class="ruby-identifier">value</span>
37
- <span class="ruby-keyword kw">end</span>
38
- <span class="ruby-constant">Frivol</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>.<span class="ruby-identifier">store_hash</span>(<span class="ruby-keyword kw">self</span>, <span class="ruby-identifier">hash</span>, <span class="ruby-identifier">bucket</span>)
39
- <span class="ruby-keyword kw">end</span>
40
-
41
- <span class="ruby-identifier">define_method</span> <span class="ruby-node">&quot;retrieve_#{bucket}&quot;</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">keys_and_defaults</span><span class="ruby-operator">|</span>
42
- <span class="ruby-identifier">hash</span> = <span class="ruby-constant">Frivol</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>.<span class="ruby-identifier">retrieve_hash</span>(<span class="ruby-keyword kw">self</span>, <span class="ruby-identifier">bucket</span>)
43
- <span class="ruby-identifier">result</span> = <span class="ruby-identifier">keys_and_defaults</span>.<span class="ruby-identifier">map</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">default</span><span class="ruby-operator">|</span>
44
- <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_s</span>] <span class="ruby-operator">||</span> (<span class="ruby-identifier">default</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Symbol</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">default</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">send</span>(<span class="ruby-identifier">default</span>)) <span class="ruby-operator">||</span> <span class="ruby-identifier">default</span>
45
- <span class="ruby-keyword kw">end</span>
46
- <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">result</span>.<span class="ruby-identifier">first</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">result</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
47
- <span class="ruby-identifier">result</span>
48
- <span class="ruby-keyword kw">end</span>
49
- <span class="ruby-keyword kw">end</span>
50
- <span class="ruby-keyword kw">end</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/frivol.rb, line 268</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">storage_expiry</span>(<span class="ruby-identifier">bucket</span> = <span class="ruby-keyword kw">nil</span>)
15
+ <span class="ruby-ivar">@frivol_storage_expiry</span> <span class="ruby-operator">||=</span> {}
16
+ <span class="ruby-ivar">@frivol_storage_expiry</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-identifier">bucket</span>.<span class="ruby-identifier">to_s</span>) <span class="ruby-operator">?</span> <span class="ruby-ivar">@frivol_storage_expiry</span>[<span class="ruby-identifier">bucket</span>.<span class="ruby-identifier">to_s</span>] <span class="ruby-operator">:</span> <span class="ruby-constant">NEVER_EXPIRE</span>
51
17
  <span class="ruby-keyword kw">end</span></pre>
52
18
  </body>
53
19
  </html>
@@ -0,0 +1,61 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>storage_bucket (Frivol::ClassMethods)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/frivol.rb, line 292</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">storage_bucket</span>(<span class="ruby-identifier">bucket</span>, <span class="ruby-identifier">options</span> = {})
15
+ <span class="ruby-identifier">time</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:expires_in</span>]
16
+ <span class="ruby-identifier">storage_expires_in</span>(<span class="ruby-identifier">time</span>, <span class="ruby-identifier">bucket</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">time</span>.<span class="ruby-identifier">nil?</span>
17
+ <span class="ruby-identifier">is_counter</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:counter</span>]
18
+
19
+ <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class_eval</span> <span class="ruby-keyword kw">do</span>
20
+ <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">is_counter</span>
21
+ <span class="ruby-identifier">define_method</span> <span class="ruby-node">&quot;store_#{bucket}&quot;</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
22
+ <span class="ruby-constant">Frivol</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>.<span class="ruby-identifier">store_counter</span>(<span class="ruby-keyword kw">self</span>, <span class="ruby-identifier">bucket</span>, <span class="ruby-identifier">value</span>)
23
+ <span class="ruby-keyword kw">end</span>
24
+
25
+ <span class="ruby-identifier">define_method</span> <span class="ruby-node">&quot;retrieve_#{bucket}&quot;</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">default</span><span class="ruby-operator">|</span>
26
+ <span class="ruby-constant">Frivol</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>.<span class="ruby-identifier">retrieve_counter</span>(<span class="ruby-keyword kw">self</span>, <span class="ruby-identifier">bucket</span>, <span class="ruby-identifier">default</span>)
27
+ <span class="ruby-keyword kw">end</span>
28
+
29
+ <span class="ruby-identifier">define_method</span> <span class="ruby-node">&quot;increment_#{bucket}&quot;</span> <span class="ruby-keyword kw">do</span>
30
+ <span class="ruby-constant">Frivol</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>.<span class="ruby-identifier">increment_counter</span>(<span class="ruby-keyword kw">self</span>, <span class="ruby-identifier">bucket</span>)
31
+ <span class="ruby-keyword kw">end</span>
32
+ <span class="ruby-keyword kw">else</span>
33
+ <span class="ruby-identifier">define_method</span> <span class="ruby-node">&quot;store_#{bucket}&quot;</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">keys_and_values</span><span class="ruby-operator">|</span>
34
+ <span class="ruby-identifier">hash</span> = <span class="ruby-constant">Frivol</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>.<span class="ruby-identifier">retrieve_hash</span>(<span class="ruby-keyword kw">self</span>, <span class="ruby-identifier">bucket</span>)
35
+ <span class="ruby-identifier">keys_and_values</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
36
+ <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_s</span>] = <span class="ruby-identifier">value</span>
37
+ <span class="ruby-keyword kw">end</span>
38
+ <span class="ruby-constant">Frivol</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>.<span class="ruby-identifier">store_hash</span>(<span class="ruby-keyword kw">self</span>, <span class="ruby-identifier">hash</span>, <span class="ruby-identifier">bucket</span>)
39
+ <span class="ruby-keyword kw">end</span>
40
+
41
+ <span class="ruby-identifier">define_method</span> <span class="ruby-node">&quot;retrieve_#{bucket}&quot;</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">keys_and_defaults</span><span class="ruby-operator">|</span>
42
+ <span class="ruby-identifier">hash</span> = <span class="ruby-constant">Frivol</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>.<span class="ruby-identifier">retrieve_hash</span>(<span class="ruby-keyword kw">self</span>, <span class="ruby-identifier">bucket</span>)
43
+ <span class="ruby-identifier">result</span> = <span class="ruby-identifier">keys_and_defaults</span>.<span class="ruby-identifier">map</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">default</span><span class="ruby-operator">|</span>
44
+ <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_s</span>] <span class="ruby-operator">||</span> (<span class="ruby-identifier">default</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Symbol</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">default</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">send</span>(<span class="ruby-identifier">default</span>)) <span class="ruby-operator">||</span> <span class="ruby-identifier">default</span>
45
+ <span class="ruby-keyword kw">end</span>
46
+ <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">result</span>.<span class="ruby-identifier">first</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">result</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
47
+ <span class="ruby-identifier">result</span>
48
+ <span class="ruby-keyword kw">end</span>
49
+ <span class="ruby-keyword kw">end</span>
50
+
51
+ <span class="ruby-identifier">define_method</span> <span class="ruby-node">&quot;delete_#{bucket}&quot;</span> <span class="ruby-keyword kw">do</span>
52
+ <span class="ruby-constant">Frivol</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>.<span class="ruby-identifier">delete_hash</span>(<span class="ruby-keyword kw">self</span>, <span class="ruby-identifier">bucket</span>)
53
+ <span class="ruby-keyword kw">end</span>
54
+
55
+ <span class="ruby-identifier">define_method</span> <span class="ruby-node">&quot;clear_#{bucket}&quot;</span> <span class="ruby-keyword kw">do</span>
56
+ <span class="ruby-constant">Frivol</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span>.<span class="ruby-identifier">clear_hash</span>(<span class="ruby-keyword kw">self</span>, <span class="ruby-identifier">bucket</span>)
57
+ <span class="ruby-keyword kw">end</span>
58
+ <span class="ruby-keyword kw">end</span>
59
+ <span class="ruby-keyword kw">end</span></pre>
60
+ </body>
61
+ </html>
@@ -90,9 +90,9 @@ with an optional storage expiry parameter
90
90
  <h3 class="section-bar">Methods</h3>
91
91
 
92
92
  <div class="name-list">
93
- <a href="#M000013">include_in</a>&nbsp;&nbsp;
94
- <a href="#M000012">redis</a>&nbsp;&nbsp;
95
- <a href="#M000011">redis_config=</a>&nbsp;&nbsp;
93
+ <a href="#M000014">include_in</a>&nbsp;&nbsp;
94
+ <a href="#M000013">redis</a>&nbsp;&nbsp;
95
+ <a href="#M000012">redis_config=</a>&nbsp;&nbsp;
96
96
  </div>
97
97
  </div>
98
98
 
@@ -114,12 +114,12 @@ with an optional storage expiry parameter
114
114
  <div id="methods">
115
115
  <h3 class="section-bar">Public Class methods</h3>
116
116
 
117
- <div id="method-M000013" class="method-detail">
118
- <a name="M000013"></a>
117
+ <div id="method-M000014" class="method-detail">
118
+ <a name="M000014"></a>
119
119
 
120
120
  <div class="method-heading">
121
- <a href="Config.src/M000013.html" target="Code" class="method-signature"
122
- onclick="popupCode('Config.src/M000013.html');return false;">
121
+ <a href="Config.src/M000014.html" target="Code" class="method-signature"
122
+ onclick="popupCode('Config.src/M000014.html');return false;">
123
123
  <span class="method-name">include_in</span><span class="method-args">(host_class, storage_expires_in = nil)</span>
124
124
  </a>
125
125
  </div>
@@ -143,12 +143,12 @@ ActiveRecord::Base and set the default storage expiry to 10 minutes
143
143
  </div>
144
144
  </div>
145
145
 
146
- <div id="method-M000012" class="method-detail">
147
- <a name="M000012"></a>
146
+ <div id="method-M000013" class="method-detail">
147
+ <a name="M000013"></a>
148
148
 
149
149
  <div class="method-heading">
150
- <a href="Config.src/M000012.html" target="Code" class="method-signature"
151
- onclick="popupCode('Config.src/M000012.html');return false;">
150
+ <a href="Config.src/M000013.html" target="Code" class="method-signature"
151
+ onclick="popupCode('Config.src/M000013.html');return false;">
152
152
  <span class="method-name">redis</span><span class="method-args">()</span>
153
153
  </a>
154
154
  </div>
@@ -160,12 +160,12 @@ Returns the configured Redis instance
160
160
  </div>
161
161
  </div>
162
162
 
163
- <div id="method-M000011" class="method-detail">
164
- <a name="M000011"></a>
163
+ <div id="method-M000012" class="method-detail">
164
+ <a name="M000012"></a>
165
165
 
166
166
  <div class="method-heading">
167
- <a href="Config.src/M000011.html" target="Code" class="method-signature"
168
- onclick="popupCode('Config.src/M000011.html');return false;">
167
+ <a href="Config.src/M000012.html" target="Code" class="method-signature"
168
+ onclick="popupCode('Config.src/M000012.html');return false;">
169
169
  <span class="method-name">redis_config=</span><span class="method-args">(config)</span>
170
170
  </a>
171
171
  </div>
@@ -5,14 +5,14 @@
5
5
 
6
6
  <html>
7
7
  <head>
8
- <title>redis (Frivol::Config)</title>
8
+ <title>redis_config= (Frivol::Config)</title>
9
9
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
10
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
11
  </head>
12
12
  <body class="standalone-code">
13
- <pre><span class="ruby-comment cmt"># File lib/frivol.rb, line 164</span>
14
- <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">redis</span>
15
- <span class="ruby-ivar">@@redis</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/frivol.rb, line 165</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">redis_config=</span>(<span class="ruby-identifier">config</span>)
15
+ <span class="ruby-ivar">@@redis</span> = <span class="ruby-constant">Redis</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">config</span>)
16
16
  <span class="ruby-keyword kw">end</span></pre>
17
17
  </body>
18
18
  </html>
@@ -5,15 +5,14 @@
5
5
 
6
6
  <html>
7
7
  <head>
8
- <title>include_in (Frivol::Config)</title>
8
+ <title>redis (Frivol::Config)</title>
9
9
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
10
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
11
  </head>
12
12
  <body class="standalone-code">
13
- <pre><span class="ruby-comment cmt"># File lib/frivol.rb, line 174</span>
14
- <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">include_in</span>(<span class="ruby-identifier">host_class</span>, <span class="ruby-identifier">storage_expires_in</span> = <span class="ruby-keyword kw">nil</span>)
15
- <span class="ruby-identifier">host_class</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">:include</span>, <span class="ruby-constant">Frivol</span>)
16
- <span class="ruby-identifier">host_class</span>.<span class="ruby-identifier">storage_expires_in</span> <span class="ruby-identifier">storage_expires_in</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">storage_expires_in</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/frivol.rb, line 170</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">redis</span>
15
+ <span class="ruby-ivar">@@redis</span>
17
16
  <span class="ruby-keyword kw">end</span></pre>
18
17
  </body>
19
18
  </html>
@@ -0,0 +1,19 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html>
7
+ <head>
8
+ <title>include_in (Frivol::Config)</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
+ </head>
12
+ <body class="standalone-code">
13
+ <pre><span class="ruby-comment cmt"># File lib/frivol.rb, line 180</span>
14
+ <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">include_in</span>(<span class="ruby-identifier">host_class</span>, <span class="ruby-identifier">storage_expires_in</span> = <span class="ruby-keyword kw">nil</span>)
15
+ <span class="ruby-identifier">host_class</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">:include</span>, <span class="ruby-constant">Frivol</span>)
16
+ <span class="ruby-identifier">host_class</span>.<span class="ruby-identifier">storage_expires_in</span> <span class="ruby-identifier">storage_expires_in</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">storage_expires_in</span>
17
+ <span class="ruby-keyword kw">end</span></pre>
18
+ </body>
19
+ </html>
@@ -10,7 +10,7 @@
10
10
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
11
  </head>
12
12
  <body class="standalone-code">
13
- <pre><span class="ruby-comment cmt"># File lib/frivol.rb, line 330</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/frivol.rb, line 354</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_json</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">a</span>)
15
15
  {
16
16
  <span class="ruby-value str">'json_class'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">name</span>,
@@ -10,7 +10,7 @@
10
10
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
11
11
  </head>
12
12
  <body class="standalone-code">
13
- <pre><span class="ruby-comment cmt"># File lib/frivol.rb, line 338</span>
13
+ <pre><span class="ruby-comment cmt"># File lib/frivol.rb, line 362</span>
14
14
  <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">json_create</span>(<span class="ruby-identifier">o</span>)
15
15
  <span class="ruby-constant">Time</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">o</span>[<span class="ruby-value str">'data'</span>])
16
16
  <span class="ruby-keyword kw">end</span></pre>
data/doc/created.rid CHANGED
@@ -1 +1 @@
1
- Fri, 15 Oct 2010 11:43:06 +0200
1
+ Fri, 22 Oct 2010 14:38:28 +0200
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Fri Oct 15 11:30:46 +0200 2010</td>
59
+ <td>Fri Oct 22 14:36:50 +0200 2010</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -118,7 +118,9 @@ The <tt>expire_storage(time)</tt> method can be used to set the expiry time
118
118
  in seconds of the temporary storage. The default is not to expire the
119
119
  storage, in which case it will live for as long as Redis keeps it.
120
120
  <tt>delete_storage</tt>, as the name suggests will immediately delete the
121
- storage.
121
+ storage, while <tt>clear_storage</tt> will clear the cache that <a
122
+ href="../../classes/Frivol.html">Frivol</a> keeps and force the next
123
+ <tt>retrieve</tt> to return to Redis for the data.
122
124
  </p>
123
125
  <p>
124
126
  Since version 0.1.5 <a href="../../classes/Frivol.html">Frivol</a> can
@@ -20,17 +20,18 @@
20
20
  <div id="index">
21
21
  <h1 class="section-bar">Methods</h1>
22
22
  <div id="index-entries">
23
+ <a href="classes/Frivol.html#M000006">clear_storage (Frivol)</a><br />
23
24
  <a href="classes/Frivol.html#M000005">delete_storage (Frivol)</a><br />
24
- <a href="classes/Frivol.html#M000006">expire_storage (Frivol)</a><br />
25
- <a href="classes/Frivol/Config.html#M000013">include_in (Frivol::Config)</a><br />
25
+ <a href="classes/Frivol.html#M000007">expire_storage (Frivol)</a><br />
26
+ <a href="classes/Frivol/Config.html#M000014">include_in (Frivol::Config)</a><br />
26
27
  <a href="classes/Time.html#M000002">json_create (Time)</a><br />
27
- <a href="classes/Frivol/Config.html#M000012">redis (Frivol::Config)</a><br />
28
- <a href="classes/Frivol/Config.html#M000011">redis_config= (Frivol::Config)</a><br />
28
+ <a href="classes/Frivol/Config.html#M000013">redis (Frivol::Config)</a><br />
29
+ <a href="classes/Frivol/Config.html#M000012">redis_config= (Frivol::Config)</a><br />
29
30
  <a href="classes/Frivol.html#M000004">retrieve (Frivol)</a><br />
30
- <a href="classes/Frivol/ClassMethods.html#M000010">storage_bucket (Frivol::ClassMethods)</a><br />
31
- <a href="classes/Frivol/ClassMethods.html#M000008">storage_expires_in (Frivol::ClassMethods)</a><br />
32
- <a href="classes/Frivol/ClassMethods.html#M000009">storage_expiry (Frivol::ClassMethods)</a><br />
33
- <a href="classes/Frivol.html#M000007">storage_key (Frivol)</a><br />
31
+ <a href="classes/Frivol/ClassMethods.html#M000011">storage_bucket (Frivol::ClassMethods)</a><br />
32
+ <a href="classes/Frivol/ClassMethods.html#M000009">storage_expires_in (Frivol::ClassMethods)</a><br />
33
+ <a href="classes/Frivol/ClassMethods.html#M000010">storage_expiry (Frivol::ClassMethods)</a><br />
34
+ <a href="classes/Frivol.html#M000008">storage_key (Frivol)</a><br />
34
35
  <a href="classes/Frivol.html#M000003">store (Frivol)</a><br />
35
36
  <a href="classes/Time.html#M000001">to_json (Time)</a><br />
36
37
  </div>
data/frivol.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{frivol}
8
- s.version = "0.1.5"
8
+ s.version = "0.1.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Marc Heiligers"]
12
- s.date = %q{2010-10-15}
12
+ s.date = %q{2010-10-22}
13
13
  s.description = %q{Simple Redis backed temporary storage intended primarily for use with ActiveRecord models to provide caching}
14
14
  s.email = %q{marc@eternal.co.za}
15
15
  s.extra_rdoc_files = [
@@ -29,17 +29,15 @@ Gem::Specification.new do |s|
29
29
  "doc/classes/Frivol.src/M000005.html",
30
30
  "doc/classes/Frivol.src/M000006.html",
31
31
  "doc/classes/Frivol.src/M000007.html",
32
+ "doc/classes/Frivol.src/M000008.html",
32
33
  "doc/classes/Frivol/ClassMethods.html",
33
- "doc/classes/Frivol/ClassMethods.src/M000007.html",
34
- "doc/classes/Frivol/ClassMethods.src/M000008.html",
35
34
  "doc/classes/Frivol/ClassMethods.src/M000009.html",
36
35
  "doc/classes/Frivol/ClassMethods.src/M000010.html",
36
+ "doc/classes/Frivol/ClassMethods.src/M000011.html",
37
37
  "doc/classes/Frivol/Config.html",
38
- "doc/classes/Frivol/Config.src/M000009.html",
39
- "doc/classes/Frivol/Config.src/M000010.html",
40
- "doc/classes/Frivol/Config.src/M000011.html",
41
38
  "doc/classes/Frivol/Config.src/M000012.html",
42
39
  "doc/classes/Frivol/Config.src/M000013.html",
40
+ "doc/classes/Frivol/Config.src/M000014.html",
43
41
  "doc/classes/Time.html",
44
42
  "doc/classes/Time.src/M000001.html",
45
43
  "doc/classes/Time.src/M000002.html",
data/lib/frivol.rb CHANGED
@@ -27,7 +27,8 @@
27
27
  #
28
28
  # The <tt>expire_storage(time)</tt> method can be used to set the expiry time in seconds of the temporary storage.
29
29
  # The default is not to expire the storage, in which case it will live for as long as Redis keeps it.
30
- # <tt>delete_storage</tt>, as the name suggests will immediately delete the storage.
30
+ # <tt>delete_storage</tt>, as the name suggests will immediately delete the storage, while <tt>clear_storage</tt>
31
+ # will clear the cache that Frivol keeps and force the next <tt>retrieve</tt> to return to Redis for the data.
31
32
  #
32
33
  # Since version 0.1.5 Frivol can create different storage buckets. Note that this introduces a breaking change
33
34
  # to the <tt>storage_key</tt> method if you have overriden it. It now takes a +bucket+ parameter.
@@ -120,11 +121,16 @@ module Frivol
120
121
  result
121
122
  end
122
123
 
123
- # Deletes the stored values.
124
+ # Deletes the stored values (and clears the cache).
124
125
  def delete_storage
125
126
  Frivol::Helpers.delete_hash self
126
127
  end
127
128
 
129
+ # Clears the cached values and forces the next retrieve to fetch from Redis.
130
+ def clear_storage
131
+ Frivol::Helpers.clear_hash self
132
+ end
133
+
128
134
  # Expire the stored data in +time+ seconds.
129
135
  def expire_storage(time, bucket = nil)
130
136
  return if time.nil?
@@ -179,7 +185,7 @@ module Frivol
179
185
 
180
186
  module Helpers #:nodoc:
181
187
  def self.store_hash(instance, hash, bucket = nil)
182
- data, is_new = get_hash_and_is_new(instance, bucket)
188
+ data, is_new = get_data_and_is_new instance
183
189
  data[bucket.to_s] = hash
184
190
 
185
191
  key = instance.send(:storage_key, bucket)
@@ -190,39 +196,49 @@ module Frivol
190
196
  Frivol::Config.redis.expire(key, time) if time != Frivol::NEVER_EXPIRE
191
197
  is_new[bucket.to_s] = false
192
198
  end
199
+
200
+ self.set_data_and_is_new instance, data, is_new
193
201
  end
194
202
 
195
203
  def self.retrieve_hash(instance, bucket = nil)
196
- data, is_new = get_hash_and_is_new(instance, bucket)
204
+ data, is_new = get_data_and_is_new instance
197
205
  return data[bucket.to_s] if data.key?(bucket.to_s)
198
206
  key = instance.send(:storage_key, bucket)
199
207
  json = Frivol::Config.redis[key]
200
208
 
201
209
  is_new[bucket.to_s] = json.nil?
202
- instance.instance_variable_set :@frivol_is_new, is_new
203
210
 
204
211
  hash = json.nil? ? {} : JSON.parse(json)
205
212
  data[bucket.to_s] = hash
206
- instance.instance_variable_set :@frivol_data, data
207
213
 
214
+ self.set_data_and_is_new instance, data, is_new
208
215
  hash
209
216
  end
210
217
 
211
218
  def self.delete_hash(instance, bucket = nil)
212
219
  key = instance.send(:storage_key, bucket)
213
220
  Frivol::Config.redis.del key
214
-
221
+ clear_hash(instance, bucket)
222
+ end
223
+
224
+ def self.clear_hash(instance, bucket = nil)
225
+ key = instance.send(:storage_key, bucket)
215
226
  data = instance.instance_variable_defined?(:@frivol_data) ? instance.instance_variable_get(:@frivol_data) : {}
216
227
  data.delete(bucket.to_s)
217
228
  instance.instance_variable_set :@frivol_data, data
218
229
  end
219
230
 
220
- def self.get_hash_and_is_new(instance, bucket)
231
+ def self.get_data_and_is_new(instance)
221
232
  data = instance.instance_variable_defined?(:@frivol_data) ? instance.instance_variable_get(:@frivol_data) : {}
222
233
  is_new = instance.instance_variable_defined?(:@frivol_is_new) ? instance.instance_variable_get(:@frivol_is_new) : {}
223
234
  [data, is_new]
224
235
  end
225
236
 
237
+ def self.set_data_and_is_new(instance, data, is_new)
238
+ instance.instance_variable_set :@frivol_data, data
239
+ instance.instance_variable_set :@frivol_is_new, is_new
240
+ end
241
+
226
242
  def self.store_counter(instance, counter, value)
227
243
  key = instance.send(:storage_key, counter)
228
244
  Frivol::Config.redis[key] = value
@@ -309,6 +325,14 @@ module Frivol
309
325
  result
310
326
  end
311
327
  end
328
+
329
+ define_method "delete_#{bucket}" do
330
+ Frivol::Helpers.delete_hash(self, bucket)
331
+ end
332
+
333
+ define_method "clear_#{bucket}" do
334
+ Frivol::Helpers.clear_hash(self, bucket)
335
+ end
312
336
  end
313
337
  end
314
338
 
data/test/test_frivol.rb CHANGED
@@ -4,6 +4,7 @@ class TestFrivol < Test::Unit::TestCase
4
4
  def setup
5
5
  # fake_redis # Comment out this line to test against a real live Redis
6
6
  Frivol::Config.redis_config = { :thread_safe => true } # This will connect to a default Redis setup, otherwise set to { :host => "localhost", :port => 6379 }, for example
7
+ Frivol::Config.redis.flushdb
7
8
  end
8
9
 
9
10
  def teardown
@@ -258,6 +259,7 @@ class TestFrivol < Test::Unit::TestCase
258
259
  assert_equal 11, t.load_blue
259
260
  end
260
261
 
262
+ # Note: this test will fail from time to time using fake_redis because fake_redis is not thread safe
261
263
  should "have thread safe counters" do
262
264
  class ThreadCounterTestClass < TestClass
263
265
  storage_bucket :blue, :counter => true
@@ -288,4 +290,46 @@ class TestFrivol < Test::Unit::TestCase
288
290
 
289
291
  assert_equal 1010, t.load_blue
290
292
  end
293
+
294
+ should "be able to delete storage for a bucket" do
295
+ class DeleteBucketTestClass < TestClass
296
+ storage_bucket :silver
297
+
298
+ def save_silver
299
+ store_silver :value => "value"
300
+ end
301
+
302
+ def load_silver
303
+ retrieve_silver :value => "default"
304
+ end
305
+ end
306
+ t = DeleteBucketTestClass.new
307
+ t.save_silver
308
+ assert_equal "value", t.load_silver
309
+ t.delete_silver
310
+ assert_equal "default", t.load_silver
311
+ end
312
+
313
+ should "be able to clear cached storage for a bucket" do
314
+ class ClearBucketTestClass < TestClass
315
+ storage_bucket :gold
316
+
317
+ def save_gold
318
+ store_gold :value => "value"
319
+ end
320
+
321
+ def load_gold
322
+ retrieve_gold :value => "default"
323
+ end
324
+ end
325
+ t = ClearBucketTestClass.new
326
+ t.save_gold
327
+ assert_equal "value", t.load_gold
328
+ t.clear_gold
329
+ # ensure we're getting the result from Redis and not the cache
330
+ Frivol::Config.redis.expects(:[]).with(t.storage_key(:gold)).once.returns({ :value => "value" }.to_json)
331
+ assert_equal "value", t.load_gold
332
+ end
333
+
334
+
291
335
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: frivol
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 5
10
- version: 0.1.5
9
+ - 6
10
+ version: 0.1.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Marc Heiligers
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-15 00:00:00 +02:00
18
+ date: 2010-10-22 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -88,17 +88,15 @@ files:
88
88
  - doc/classes/Frivol.src/M000005.html
89
89
  - doc/classes/Frivol.src/M000006.html
90
90
  - doc/classes/Frivol.src/M000007.html
91
+ - doc/classes/Frivol.src/M000008.html
91
92
  - doc/classes/Frivol/ClassMethods.html
92
- - doc/classes/Frivol/ClassMethods.src/M000007.html
93
- - doc/classes/Frivol/ClassMethods.src/M000008.html
94
93
  - doc/classes/Frivol/ClassMethods.src/M000009.html
95
94
  - doc/classes/Frivol/ClassMethods.src/M000010.html
95
+ - doc/classes/Frivol/ClassMethods.src/M000011.html
96
96
  - doc/classes/Frivol/Config.html
97
- - doc/classes/Frivol/Config.src/M000009.html
98
- - doc/classes/Frivol/Config.src/M000010.html
99
- - doc/classes/Frivol/Config.src/M000011.html
100
97
  - doc/classes/Frivol/Config.src/M000012.html
101
98
  - doc/classes/Frivol/Config.src/M000013.html
99
+ - doc/classes/Frivol/Config.src/M000014.html
102
100
  - doc/classes/Time.html
103
101
  - doc/classes/Time.src/M000001.html
104
102
  - doc/classes/Time.src/M000002.html
@@ -1,18 +0,0 @@
1
- <?xml version="1.0" encoding="iso-8859-1"?>
2
- <!DOCTYPE html
3
- PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
-
6
- <html>
7
- <head>
8
- <title>storage_expires_in (Frivol::ClassMethods)</title>
9
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
- <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
- </head>
12
- <body class="standalone-code">
13
- <pre><span class="ruby-comment cmt"># File lib/frivol.rb, line 169</span>
14
- <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">storage_expires_in</span>(<span class="ruby-identifier">time</span>)
15
- <span class="ruby-ivar">@frivol_storage_expiry</span> = <span class="ruby-identifier">time</span>
16
- <span class="ruby-keyword kw">end</span></pre>
17
- </body>
18
- </html>
@@ -1,19 +0,0 @@
1
- <?xml version="1.0" encoding="iso-8859-1"?>
2
- <!DOCTYPE html
3
- PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
-
6
- <html>
7
- <head>
8
- <title>storage_expires_in (Frivol::ClassMethods)</title>
9
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
- <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
- </head>
12
- <body class="standalone-code">
13
- <pre><span class="ruby-comment cmt"># File lib/frivol.rb, line 246</span>
14
- <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">storage_expires_in</span>(<span class="ruby-identifier">time</span>, <span class="ruby-identifier">bucket</span> = <span class="ruby-keyword kw">nil</span>)
15
- <span class="ruby-ivar">@frivol_storage_expiry</span> <span class="ruby-operator">||=</span> {}
16
- <span class="ruby-ivar">@frivol_storage_expiry</span>[<span class="ruby-identifier">bucket</span>.<span class="ruby-identifier">to_s</span>] = <span class="ruby-identifier">time</span>
17
- <span class="ruby-keyword kw">end</span></pre>
18
- </body>
19
- </html>
@@ -1,18 +0,0 @@
1
- <?xml version="1.0" encoding="iso-8859-1"?>
2
- <!DOCTYPE html
3
- PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
-
6
- <html>
7
- <head>
8
- <title>redis_config= (Frivol::Config)</title>
9
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
- <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
- </head>
12
- <body class="standalone-code">
13
- <pre><span class="ruby-comment cmt"># File lib/frivol.rb, line 121</span>
14
- <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">redis_config=</span>(<span class="ruby-identifier">config</span>)
15
- <span class="ruby-ivar">@@redis</span> = <span class="ruby-constant">Redis</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">config</span>)
16
- <span class="ruby-keyword kw">end</span></pre>
17
- </body>
18
- </html>
@@ -1,18 +0,0 @@
1
- <?xml version="1.0" encoding="iso-8859-1"?>
2
- <!DOCTYPE html
3
- PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
-
6
- <html>
7
- <head>
8
- <title>redis (Frivol::Config)</title>
9
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
- <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
- </head>
12
- <body class="standalone-code">
13
- <pre><span class="ruby-comment cmt"># File lib/frivol.rb, line 126</span>
14
- <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">redis</span>
15
- <span class="ruby-ivar">@@redis</span>
16
- <span class="ruby-keyword kw">end</span></pre>
17
- </body>
18
- </html>
@@ -1,18 +0,0 @@
1
- <?xml version="1.0" encoding="iso-8859-1"?>
2
- <!DOCTYPE html
3
- PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
-
6
- <html>
7
- <head>
8
- <title>redis_config= (Frivol::Config)</title>
9
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
- <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
11
- </head>
12
- <body class="standalone-code">
13
- <pre><span class="ruby-comment cmt"># File lib/frivol.rb, line 159</span>
14
- <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">redis_config=</span>(<span class="ruby-identifier">config</span>)
15
- <span class="ruby-ivar">@@redis</span> = <span class="ruby-constant">Redis</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">config</span>)
16
- <span class="ruby-keyword kw">end</span></pre>
17
- </body>
18
- </html>