cachetastic 1.5.0 → 1.6.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.
- data/doc/classes/ActiveRecord/Base.html +188 -0
- data/doc/classes/CGI/Session/CachetasticStore.html +124 -0
- data/doc/classes/Cachetastic/Adapters/Base.html +331 -0
- data/doc/classes/Cachetastic/Adapters/Drb.html +332 -0
- data/doc/classes/Cachetastic/Adapters/File.html +248 -0
- data/doc/classes/Cachetastic/Adapters/FileBase.html +309 -0
- data/doc/classes/Cachetastic/Adapters/HtmlFile.html +224 -0
- data/doc/classes/Cachetastic/Adapters/LocalMemory.html +346 -0
- data/doc/classes/Cachetastic/Adapters/Memcache.html +498 -0
- data/doc/classes/Cachetastic/Cacheable.html +264 -0
- data/doc/classes/Cachetastic/Cacheable/ClassAndInstanceMethods.html +287 -0
- data/doc/classes/Cachetastic/Cacheable/ClassOnlyMethods.html +200 -0
- data/doc/classes/Cachetastic/Caches/Base.html +672 -0
- data/doc/classes/Cachetastic/Caches/Base/RegisteredCaches.html +179 -0
- data/doc/classes/Cachetastic/Caches/MackSessionCache.html +119 -0
- data/doc/classes/Cachetastic/Caches/PageCache.html +121 -0
- data/doc/classes/Cachetastic/Caches/RailsSessionCache.html +154 -0
- data/doc/classes/Cachetastic/Connection.html +212 -0
- data/doc/classes/Cachetastic/Errors/UnsupportedAdapter.html +146 -0
- data/doc/classes/Cachetastic/Logger.html +189 -0
- data/doc/classes/Object.html +152 -0
- data/doc/created.rid +1 -0
- data/doc/files/README.html +207 -0
- data/doc/files/lib/adapters/cachetastic_adapters_base_rb.html +139 -0
- data/doc/files/lib/adapters/cachetastic_adapters_drb_rb.html +115 -0
- data/doc/files/lib/adapters/cachetastic_adapters_file_base_rb.html +109 -0
- data/doc/files/lib/adapters/cachetastic_adapters_file_rb.html +121 -0
- data/doc/files/lib/adapters/cachetastic_adapters_html_file_rb.html +137 -0
- data/doc/files/lib/adapters/cachetastic_adapters_local_memory_rb.html +109 -0
- data/doc/files/lib/adapters/cachetastic_adapters_memcache_rb.html +127 -0
- data/doc/files/lib/adapters/cachetastic_adapters_store_object_rb.html +101 -0
- data/doc/files/lib/caches/cachetastic_caches_base_rb.html +108 -0
- data/doc/files/lib/caches/cachetastic_caches_mack_session_cache_rb.html +107 -0
- data/doc/files/lib/caches/cachetastic_caches_page_cache_rb.html +109 -0
- data/doc/files/lib/caches/cachetastic_caches_rails_session_cache_rb.html +107 -0
- data/doc/files/lib/cachetastic_cacheable_rb.html +101 -0
- data/doc/files/lib/cachetastic_connection_rb.html +107 -0
- data/doc/files/lib/cachetastic_logger_rb.html +107 -0
- data/doc/files/lib/cachetastic_rb.html +222 -0
- data/doc/files/lib/errors/cachetastic_errors_unsupported_adapter_rb.html +101 -0
- data/doc/files/lib/rails_extensions/cachetastic_active_record_base_rb.html +101 -0
- data/doc/files/lib/rails_extensions/cgi_session_cachetastic_store_rb.html +109 -0
- data/doc/files/lib/ruby_extensions/object_rb.html +101 -0
- data/doc/fr_class_index.html +47 -0
- data/doc/fr_file_index.html +47 -0
- data/doc/fr_method_index.html +100 -0
- data/doc/index.html +24 -0
- data/doc/rdoc-style.css +208 -0
- data/lib/cachetastic.rb +21 -23
- data/lib/cachetastic_cacheable.rb +202 -0
- data/lib/rails_extensions/cachetastic_active_record_base.rb +12 -39
- data/lib/ruby_extensions/object.rb +8 -0
- data/test/active_record_test.rb +8 -8
- data/test/cacheable_test.rb +72 -0
- metadata +52 -2
- data/lib/helpers/cachetastic_helpers_active_record.rb +0 -46
@@ -0,0 +1,264 @@
|
|
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 xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
+
<head>
|
8
|
+
<title>Module: Cachetastic::Cacheable</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
+
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
12
|
+
<script type="text/javascript">
|
13
|
+
// <![CDATA[
|
14
|
+
|
15
|
+
function popupCode( url ) {
|
16
|
+
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
17
|
+
}
|
18
|
+
|
19
|
+
function toggleCode( id ) {
|
20
|
+
if ( document.getElementById )
|
21
|
+
elem = document.getElementById( id );
|
22
|
+
else if ( document.all )
|
23
|
+
elem = eval( "document.all." + id );
|
24
|
+
else
|
25
|
+
return false;
|
26
|
+
|
27
|
+
elemStyle = elem.style;
|
28
|
+
|
29
|
+
if ( elemStyle.display != "block" ) {
|
30
|
+
elemStyle.display = "block"
|
31
|
+
} else {
|
32
|
+
elemStyle.display = "none"
|
33
|
+
}
|
34
|
+
|
35
|
+
return true;
|
36
|
+
}
|
37
|
+
|
38
|
+
// Make codeblocks hidden by default
|
39
|
+
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
40
|
+
|
41
|
+
// ]]>
|
42
|
+
</script>
|
43
|
+
|
44
|
+
</head>
|
45
|
+
<body>
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
<div id="classHeader">
|
50
|
+
<table class="header-table">
|
51
|
+
<tr class="top-aligned-row">
|
52
|
+
<td><strong>Module</strong></td>
|
53
|
+
<td class="class-name-in-header">Cachetastic::Cacheable</td>
|
54
|
+
</tr>
|
55
|
+
<tr class="top-aligned-row">
|
56
|
+
<td><strong>In:</strong></td>
|
57
|
+
<td>
|
58
|
+
<a href="../../files/lib/cachetastic_rb.html">
|
59
|
+
lib/cachetastic.rb
|
60
|
+
</a>
|
61
|
+
<br />
|
62
|
+
<a href="../../files/lib/cachetastic_cacheable_rb.html">
|
63
|
+
lib/cachetastic_cacheable.rb
|
64
|
+
</a>
|
65
|
+
<br />
|
66
|
+
</td>
|
67
|
+
</tr>
|
68
|
+
|
69
|
+
</table>
|
70
|
+
</div>
|
71
|
+
<!-- banner header -->
|
72
|
+
|
73
|
+
<div id="bodyContent">
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
<div id="contextContent">
|
78
|
+
|
79
|
+
<div id="description">
|
80
|
+
<p>
|
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.
|
88
|
+
</p>
|
89
|
+
<p>
|
90
|
+
Example:
|
91
|
+
</p>
|
92
|
+
<pre>
|
93
|
+
class Person
|
94
|
+
include Cachetastic::Cacheable
|
95
|
+
|
96
|
+
attr_accessor :name
|
97
|
+
|
98
|
+
def cachetastic_key
|
99
|
+
self.name
|
100
|
+
end
|
101
|
+
|
102
|
+
def always_the_same(x, y)
|
103
|
+
cacher("always_the_same") do
|
104
|
+
x + y
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
</pre>
|
110
|
+
|
111
|
+
</div>
|
112
|
+
|
113
|
+
|
114
|
+
</div>
|
115
|
+
|
116
|
+
<div id="method-list">
|
117
|
+
<h3 class="section-bar">Methods</h3>
|
118
|
+
|
119
|
+
<div class="name-list">
|
120
|
+
<a href="#M000047">cache_self</a>
|
121
|
+
<a href="#M000048">uncache_self</a>
|
122
|
+
</div>
|
123
|
+
</div>
|
124
|
+
|
125
|
+
</div>
|
126
|
+
|
127
|
+
|
128
|
+
<!-- if includes -->
|
129
|
+
|
130
|
+
<div id="section">
|
131
|
+
|
132
|
+
<div id="class-list">
|
133
|
+
<h3 class="section-bar">Classes and Modules</h3>
|
134
|
+
|
135
|
+
Module <a href="Cacheable/ClassAndInstanceMethods.html" class="link">Cachetastic::Cacheable::ClassAndInstanceMethods</a><br />
|
136
|
+
Module <a href="Cacheable/ClassOnlyMethods.html" class="link">Cachetastic::Cacheable::ClassOnlyMethods</a><br />
|
137
|
+
|
138
|
+
</div>
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
|
146
|
+
<!-- if method_list -->
|
147
|
+
<div id="methods">
|
148
|
+
<h3 class="section-bar">Public Instance methods</h3>
|
149
|
+
|
150
|
+
<div id="method-M000047" class="method-detail">
|
151
|
+
<a name="M000047"></a>
|
152
|
+
|
153
|
+
<div class="method-heading">
|
154
|
+
<a href="#M000047" class="method-signature">
|
155
|
+
<span class="method-name">cache_self</span><span class="method-args">()</span>
|
156
|
+
</a>
|
157
|
+
</div>
|
158
|
+
|
159
|
+
<div class="method-description">
|
160
|
+
<p>
|
161
|
+
Unless the object‘s cachetastic_key method returns nil this method
|
162
|
+
will store the object in the cache using the object‘s cachetastic_key
|
163
|
+
as the key. You <b>MUST</b> create an instance level method called
|
164
|
+
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
|
166
|
+
href="Cacheable.html#M000047">cache_self</a> and <a
|
167
|
+
href="Cacheable.html#M000048">uncache_self</a> methods.
|
168
|
+
</p>
|
169
|
+
<p>
|
170
|
+
Example:
|
171
|
+
</p>
|
172
|
+
<pre>
|
173
|
+
class Person
|
174
|
+
include Cachetastic::Cacheable
|
175
|
+
attr_accessor :name
|
176
|
+
def cachetastic_key
|
177
|
+
self.name
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
Person.get_from_cache("Mark Bates") # => nil
|
182
|
+
p = Person.new
|
183
|
+
p.name = "Mark Bates"
|
184
|
+
p.cache_self
|
185
|
+
Person.get_from_cache("Mark Bates") # => "Mark Bates"
|
186
|
+
</pre>
|
187
|
+
<p><a class="source-toggle" href="#"
|
188
|
+
onclick="toggleCode('M000047-source');return false;">[Source]</a></p>
|
189
|
+
<div class="method-source-code" id="M000047-source">
|
190
|
+
<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>
|
195
|
+
</pre>
|
196
|
+
</div>
|
197
|
+
</div>
|
198
|
+
</div>
|
199
|
+
|
200
|
+
<div id="method-M000048" class="method-detail">
|
201
|
+
<a name="M000048"></a>
|
202
|
+
|
203
|
+
<div class="method-heading">
|
204
|
+
<a href="#M000048" class="method-signature">
|
205
|
+
<span class="method-name">uncache_self</span><span class="method-args">()</span>
|
206
|
+
</a>
|
207
|
+
</div>
|
208
|
+
|
209
|
+
<div class="method-description">
|
210
|
+
<p>
|
211
|
+
Unless the object‘s cachetastic_key method returns nil this method
|
212
|
+
will delete the object in the cache using the object‘s
|
213
|
+
cachetastic_key as the key. You <b>MUST</b> create an instance level method
|
214
|
+
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
|
216
|
+
href="Cacheable.html#M000047">cache_self</a> and <a
|
217
|
+
href="Cacheable.html#M000048">uncache_self</a> methods.
|
218
|
+
</p>
|
219
|
+
<p>
|
220
|
+
Example:
|
221
|
+
</p>
|
222
|
+
<pre>
|
223
|
+
class Person
|
224
|
+
include Cachetastic::Cacheable
|
225
|
+
attr_accessor :name
|
226
|
+
def cachetastic_key
|
227
|
+
self.name
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
Person.get_from_cache("Mark Bates") # => nil
|
232
|
+
p = Person.new
|
233
|
+
p.name = "Mark Bates"
|
234
|
+
p.cache_self
|
235
|
+
Person.get_from_cache("Mark Bates") # => "Mark Bates"
|
236
|
+
p.uncache_self
|
237
|
+
Person.get_from_cache("Mark Bates") # => nil
|
238
|
+
</pre>
|
239
|
+
<p><a class="source-toggle" href="#"
|
240
|
+
onclick="toggleCode('M000048-source');return false;">[Source]</a></p>
|
241
|
+
<div class="method-source-code" id="M000048-source">
|
242
|
+
<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>
|
247
|
+
</pre>
|
248
|
+
</div>
|
249
|
+
</div>
|
250
|
+
</div>
|
251
|
+
|
252
|
+
|
253
|
+
</div>
|
254
|
+
|
255
|
+
|
256
|
+
</div>
|
257
|
+
|
258
|
+
|
259
|
+
<div id="validator-badges">
|
260
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
261
|
+
</div>
|
262
|
+
|
263
|
+
</body>
|
264
|
+
</html>
|
@@ -0,0 +1,287 @@
|
|
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 xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
+
<head>
|
8
|
+
<title>Module: Cachetastic::Cacheable::ClassAndInstanceMethods</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
+
<link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
|
12
|
+
<script type="text/javascript">
|
13
|
+
// <![CDATA[
|
14
|
+
|
15
|
+
function popupCode( url ) {
|
16
|
+
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
17
|
+
}
|
18
|
+
|
19
|
+
function toggleCode( id ) {
|
20
|
+
if ( document.getElementById )
|
21
|
+
elem = document.getElementById( id );
|
22
|
+
else if ( document.all )
|
23
|
+
elem = eval( "document.all." + id );
|
24
|
+
else
|
25
|
+
return false;
|
26
|
+
|
27
|
+
elemStyle = elem.style;
|
28
|
+
|
29
|
+
if ( elemStyle.display != "block" ) {
|
30
|
+
elemStyle.display = "block"
|
31
|
+
} else {
|
32
|
+
elemStyle.display = "none"
|
33
|
+
}
|
34
|
+
|
35
|
+
return true;
|
36
|
+
}
|
37
|
+
|
38
|
+
// Make codeblocks hidden by default
|
39
|
+
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
40
|
+
|
41
|
+
// ]]>
|
42
|
+
</script>
|
43
|
+
|
44
|
+
</head>
|
45
|
+
<body>
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
<div id="classHeader">
|
50
|
+
<table class="header-table">
|
51
|
+
<tr class="top-aligned-row">
|
52
|
+
<td><strong>Module</strong></td>
|
53
|
+
<td class="class-name-in-header">Cachetastic::Cacheable::ClassAndInstanceMethods</td>
|
54
|
+
</tr>
|
55
|
+
<tr class="top-aligned-row">
|
56
|
+
<td><strong>In:</strong></td>
|
57
|
+
<td>
|
58
|
+
<a href="../../../files/lib/cachetastic_cacheable_rb.html">
|
59
|
+
lib/cachetastic_cacheable.rb
|
60
|
+
</a>
|
61
|
+
<br />
|
62
|
+
</td>
|
63
|
+
</tr>
|
64
|
+
|
65
|
+
</table>
|
66
|
+
</div>
|
67
|
+
<!-- banner header -->
|
68
|
+
|
69
|
+
<div id="bodyContent">
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
<div id="contextContent">
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
</div>
|
78
|
+
|
79
|
+
<div id="method-list">
|
80
|
+
<h3 class="section-bar">Methods</h3>
|
81
|
+
|
82
|
+
<div class="name-list">
|
83
|
+
<a href="#M000049">cache_class</a>
|
84
|
+
<a href="#M000050">cacher</a>
|
85
|
+
<a href="#M000051">expire_all</a>
|
86
|
+
</div>
|
87
|
+
</div>
|
88
|
+
|
89
|
+
</div>
|
90
|
+
|
91
|
+
|
92
|
+
<!-- if includes -->
|
93
|
+
|
94
|
+
<div id="section">
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
<!-- if method_list -->
|
104
|
+
<div id="methods">
|
105
|
+
<h3 class="section-bar">Public Instance methods</h3>
|
106
|
+
|
107
|
+
<div id="method-M000049" class="method-detail">
|
108
|
+
<a name="M000049"></a>
|
109
|
+
|
110
|
+
<div class="method-heading">
|
111
|
+
<a href="#M000049" class="method-signature">
|
112
|
+
<span class="method-name">cache_class</span><span class="method-args">()</span>
|
113
|
+
</a>
|
114
|
+
</div>
|
115
|
+
|
116
|
+
<div class="method-description">
|
117
|
+
<p>
|
118
|
+
Returns the <a href="../Caches/Base.html">Cachetastic::Caches::Base</a>
|
119
|
+
object associated with the object. If a cache hasn‘t been defined the
|
120
|
+
one will be created on the fly. The cache for the object is expected to be
|
121
|
+
defined as: <a
|
122
|
+
href="../Cacheable.html">Cachetastic::Cacheable</a>::{CLASS_NAME_HERE}Cache
|
123
|
+
</p>
|
124
|
+
<p>
|
125
|
+
Example:
|
126
|
+
</p>
|
127
|
+
<pre>
|
128
|
+
class Person
|
129
|
+
include Cachetastic::Cacheable
|
130
|
+
attr_accessor :name
|
131
|
+
def cachetastic_key
|
132
|
+
self.name
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
Person.cache_class # => Cachetastic::Cacheable::PersonCache
|
137
|
+
</pre>
|
138
|
+
<p><a class="source-toggle" href="#"
|
139
|
+
onclick="toggleCode('M000049-source');return false;">[Source]</a></p>
|
140
|
+
<div class="method-source-code" id="M000049-source">
|
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">"Class"</span>
|
146
|
+
45: <span class="ruby-comment cmt"># puts "n: #{n}"</span>
|
147
|
+
46: <span class="ruby-identifier">c_name</span> = <span class="ruby-node">"Cachetastic::Cacheable::#{n}Cache"</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">"#{n}Cache"</span>)
|
149
|
+
48: <span class="ruby-comment cmt"># puts "we need to create a cache for: #{c_name}"</span>
|
150
|
+
49: <span class="ruby-identifier">eval</span> <span class="ruby-node">%{
|
151
|
+
50: class #{c_name} < 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>
|
157
|
+
</pre>
|
158
|
+
</div>
|
159
|
+
</div>
|
160
|
+
</div>
|
161
|
+
|
162
|
+
<div id="method-M000050" class="method-detail">
|
163
|
+
<a name="M000050"></a>
|
164
|
+
|
165
|
+
<div class="method-heading">
|
166
|
+
<a href="#M000050" class="method-signature">
|
167
|
+
<span class="method-name">cacher</span><span class="method-args">(key, expiry = 0) {|| ...}</span>
|
168
|
+
</a>
|
169
|
+
</div>
|
170
|
+
|
171
|
+
<div class="method-description">
|
172
|
+
<p>
|
173
|
+
How much did I want to call this method cache?? It originally was that, but
|
174
|
+
in Rails 2.0 they decided to use that name, so I had to rename this method.
|
175
|
+
This method will attempt to get an object from the cache for a given key.
|
176
|
+
If the object is nil and a block is given the block will be run, and the
|
177
|
+
results of the block will be automatically cached.
|
178
|
+
</p>
|
179
|
+
<p>
|
180
|
+
Example:
|
181
|
+
</p>
|
182
|
+
<pre>
|
183
|
+
class Person
|
184
|
+
include Cachetastic::Cacheable
|
185
|
+
attr_accessor :name
|
186
|
+
def cachetastic_key
|
187
|
+
self.name
|
188
|
+
end
|
189
|
+
def always_the_same(x,y)
|
190
|
+
cacher("always_the_same") do
|
191
|
+
x + y
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
</pre>
|
196
|
+
<p>
|
197
|
+
Person.new.always_the_same(1,2) # => 3 Person.new.always_the_same(2,2) #
|
198
|
+
=> 3 Person.new.always_the_same(3,3) # => 3
|
199
|
+
Person.cacher("always_the_same") # => 3
|
200
|
+
Person.get_from_cache("always_the_same") # => 3
|
201
|
+
Cachetastic::Cacheable::PersonCache.get("always_the_same") #
|
202
|
+
=> 3
|
203
|
+
</p>
|
204
|
+
<p>
|
205
|
+
Person.cacher("say_hi") {"Hi There"} # => "Hi
|
206
|
+
There" Person.get_from_cache("say_hi") # => "Hi
|
207
|
+
There" Cachetastic::Cacheable::PersonCache.get("say_hi") #
|
208
|
+
=> "Hi There"
|
209
|
+
</p>
|
210
|
+
<p><a class="source-toggle" href="#"
|
211
|
+
onclick="toggleCode('M000050-source');return false;">[Source]</a></p>
|
212
|
+
<div class="method-source-code" id="M000050-source">
|
213
|
+
<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>
|
223
|
+
</pre>
|
224
|
+
</div>
|
225
|
+
</div>
|
226
|
+
</div>
|
227
|
+
|
228
|
+
<div id="method-M000051" class="method-detail">
|
229
|
+
<a name="M000051"></a>
|
230
|
+
|
231
|
+
<div class="method-heading">
|
232
|
+
<a href="#M000051" class="method-signature">
|
233
|
+
<span class="method-name">expire_all</span><span class="method-args">()</span>
|
234
|
+
</a>
|
235
|
+
</div>
|
236
|
+
|
237
|
+
<div class="method-description">
|
238
|
+
<p>
|
239
|
+
Expires the entire cache associated with this objects‘s cache.
|
240
|
+
</p>
|
241
|
+
<p>
|
242
|
+
Example:
|
243
|
+
</p>
|
244
|
+
<pre>
|
245
|
+
class Person
|
246
|
+
include Cachetastic::Cacheable
|
247
|
+
attr_accessor :name
|
248
|
+
def cachetastic_key
|
249
|
+
self.name
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
Person.set_into_cache(1, "one")
|
254
|
+
Person.get_from_cache(1) # => "one"
|
255
|
+
Person.expire_all
|
256
|
+
Person.get_from_cache(1) # => nil
|
257
|
+
Person.set_into_cache(1, "one")
|
258
|
+
Person.get_from_cache(1) # => "one"
|
259
|
+
Cachetastic::Cacheable::PersonCache.expire_all
|
260
|
+
Person.get_from_cache(1) # => nil
|
261
|
+
</pre>
|
262
|
+
<p><a class="source-toggle" href="#"
|
263
|
+
onclick="toggleCode('M000051-source');return false;">[Source]</a></p>
|
264
|
+
<div class="method-source-code" id="M000051-source">
|
265
|
+
<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>
|
270
|
+
</pre>
|
271
|
+
</div>
|
272
|
+
</div>
|
273
|
+
</div>
|
274
|
+
|
275
|
+
|
276
|
+
</div>
|
277
|
+
|
278
|
+
|
279
|
+
</div>
|
280
|
+
|
281
|
+
|
282
|
+
<div id="validator-badges">
|
283
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
284
|
+
</div>
|
285
|
+
|
286
|
+
</body>
|
287
|
+
</html>
|