unicache 0.0.1
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/CHANGELOG.rdoc +3 -0
- data/LICENSE +20 -0
- data/README.rdoc +15 -0
- data/Rakefile +28 -0
- data/doc/UniCache.html +1905 -0
- data/doc/UniCache/CallbackError.html +142 -0
- data/doc/UniCache/Error.html +138 -0
- data/doc/UniCache/FetchError.html +142 -0
- data/doc/UniCache/LruEviction.html +583 -0
- data/doc/UniCache/RemoveError.html +142 -0
- data/doc/UniCache/SizeError.html +142 -0
- data/doc/_index.html +203 -0
- data/doc/class_list.html +53 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +57 -0
- data/doc/css/style.css +338 -0
- data/doc/file.CHANGELOG.html +79 -0
- data/doc/file.README.html +88 -0
- data/doc/file_list.html +58 -0
- data/doc/frames.html +28 -0
- data/doc/index.html +88 -0
- data/doc/js/app.js +214 -0
- data/doc/js/full_list.js +178 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +196 -0
- data/doc/top-level-namespace.html +112 -0
- data/lib/unicache.rb +498 -0
- data/test/test_all.rb +248 -0
- metadata +79 -0
data/CHANGELOG.rdoc
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 tero.isannainen@gmail.com
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
= UniCache
|
2
|
+
|
3
|
+
== Description
|
4
|
+
|
5
|
+
UniCache is a universal purpose cache with Least Recently Used
|
6
|
+
replacement policy by default. Cache can be configured to use another
|
7
|
+
policy.
|
8
|
+
|
9
|
+
UniCache is intended to be Thread safe.
|
10
|
+
|
11
|
+
User can register callbacks that are run at various UniCache events.
|
12
|
+
|
13
|
+
== Documentation
|
14
|
+
|
15
|
+
Main documentation is generated from UniCache source.
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rake/testtask'
|
2
|
+
|
3
|
+
Rake::TestTask.new do |t|
|
4
|
+
t.libs << 'test'
|
5
|
+
end
|
6
|
+
|
7
|
+
desc "Run tests"
|
8
|
+
task :default => :test
|
9
|
+
|
10
|
+
task :cleanup_test do
|
11
|
+
sh "rm -rf test/test"
|
12
|
+
end
|
13
|
+
|
14
|
+
task :doc do
|
15
|
+
sh "yardoc lib/* - README.rdoc CHANGELOG.rdoc"
|
16
|
+
end
|
17
|
+
|
18
|
+
task :build => :doc do
|
19
|
+
sh "gem build unicache.gemspec"
|
20
|
+
end
|
21
|
+
|
22
|
+
task :publish do
|
23
|
+
if Dir.glob('unicache-*gem').length == 1
|
24
|
+
sh "gem push unicache*.gem"
|
25
|
+
else
|
26
|
+
raise "Multiple gems in the directory..."
|
27
|
+
end
|
28
|
+
end
|
data/doc/UniCache.html
ADDED
@@ -0,0 +1,1905 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
6
|
+
<title>
|
7
|
+
Class: UniCache
|
8
|
+
|
9
|
+
— Documentation by YARD 0.8.6.1
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
|
16
|
+
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
18
|
+
hasFrames = window.top.frames.main ? true : false;
|
19
|
+
relpath = '';
|
20
|
+
framesUrl = "frames.html#!" + escape(window.location.href);
|
21
|
+
</script>
|
22
|
+
|
23
|
+
|
24
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
25
|
+
|
26
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
27
|
+
|
28
|
+
|
29
|
+
</head>
|
30
|
+
<body>
|
31
|
+
<div id="header">
|
32
|
+
<div id="menu">
|
33
|
+
|
34
|
+
<a href="_index.html">Index (U)</a> »
|
35
|
+
|
36
|
+
|
37
|
+
<span class="title">UniCache</span>
|
38
|
+
|
39
|
+
|
40
|
+
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
|
41
|
+
</div>
|
42
|
+
|
43
|
+
<div id="search">
|
44
|
+
|
45
|
+
<a class="full_list_link" id="class_list_link"
|
46
|
+
href="class_list.html">
|
47
|
+
Class List
|
48
|
+
</a>
|
49
|
+
|
50
|
+
<a class="full_list_link" id="method_list_link"
|
51
|
+
href="method_list.html">
|
52
|
+
Method List
|
53
|
+
</a>
|
54
|
+
|
55
|
+
<a class="full_list_link" id="file_list_link"
|
56
|
+
href="file_list.html">
|
57
|
+
File List
|
58
|
+
</a>
|
59
|
+
|
60
|
+
</div>
|
61
|
+
<div class="clear"></div>
|
62
|
+
</div>
|
63
|
+
|
64
|
+
<iframe id="search_frame"></iframe>
|
65
|
+
|
66
|
+
<div id="content"><h1>Class: UniCache
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
</h1>
|
71
|
+
|
72
|
+
<dl class="box">
|
73
|
+
|
74
|
+
<dt class="r1">Inherits:</dt>
|
75
|
+
<dd class="r1">
|
76
|
+
<span class="inheritName">Hash</span>
|
77
|
+
|
78
|
+
<ul class="fullTree">
|
79
|
+
<li>Object</li>
|
80
|
+
|
81
|
+
<li class="next">Hash</li>
|
82
|
+
|
83
|
+
<li class="next">UniCache</li>
|
84
|
+
|
85
|
+
</ul>
|
86
|
+
<a href="#" class="inheritanceTree">show all</a>
|
87
|
+
|
88
|
+
</dd>
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
<dt class="r2 last">Defined in:</dt>
|
99
|
+
<dd class="r2 last">lib/unicache.rb</dd>
|
100
|
+
|
101
|
+
</dl>
|
102
|
+
<div class="clear"></div>
|
103
|
+
|
104
|
+
<h2>Overview</h2><div class="docstring">
|
105
|
+
<div class="discussion">
|
106
|
+
|
107
|
+
<p>UniCache is Universal purpose Cache with Least Recently Used replacement
|
108
|
+
policy by default. Cache can be configured with another policy.</p>
|
109
|
+
|
110
|
+
<p>UniCache is intended to be Thread safe.</p>
|
111
|
+
|
112
|
+
<p>User can register callbacks that are run at various UniCache events.
|
113
|
+
":getdata" callback is used to retreive cache data if not in cache. Others
|
114
|
+
do not effect the UniCache state.</p>
|
115
|
+
|
116
|
+
<p>Usage example:</p>
|
117
|
+
|
118
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>unicache</span><span class='tstring_end'>'</span></span>
|
119
|
+
|
120
|
+
<span class='comment'># Create cache with size 2.
|
121
|
+
</span><span class='id identifier rubyid_c'>c</span> <span class='op'>=</span> <span class='const'>UniCache</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span> <span class='int'>2</span> <span class='rparen'>)</span>
|
122
|
+
|
123
|
+
<span class='comment'># Register callbacks for some events (two for hit).
|
124
|
+
</span><span class='id identifier rubyid_c'>c</span><span class='period'>.</span><span class='id identifier rubyid_registerCallback'>registerCallback</span><span class='lparen'>(</span> <span class='symbol'>:hit</span><span class='comma'>,</span> <span class='const'>Proc</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_k'>k</span><span class='comma'>,</span><span class='id identifier rubyid_v'>v</span><span class='op'>|</span> <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Hit: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_k'>k</span><span class='rbrace'>}</span><span class='tstring_content'>:</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_v'>v</span><span class='rbrace'>}</span><span class='tstring_end'>"</span></span> <span class='rbrace'>}</span> <span class='rparen'>)</span>
|
125
|
+
<span class='id identifier rubyid_c'>c</span><span class='period'>.</span><span class='id identifier rubyid_registerCallback'>registerCallback</span><span class='lparen'>(</span> <span class='symbol'>:hit</span><span class='comma'>,</span> <span class='const'>Proc</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_k'>k</span><span class='comma'>,</span><span class='id identifier rubyid_v'>v</span><span class='op'>|</span> <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Found: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_k'>k</span><span class='rbrace'>}</span><span class='tstring_content'>:</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_v'>v</span><span class='rbrace'>}</span><span class='tstring_end'>"</span></span> <span class='rbrace'>}</span> <span class='rparen'>)</span>
|
126
|
+
<span class='id identifier rubyid_c'>c</span><span class='period'>.</span><span class='id identifier rubyid_registerCallback'>registerCallback</span><span class='lparen'>(</span> <span class='symbol'>:miss</span><span class='comma'>,</span> <span class='const'>Proc</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_k'>k</span><span class='comma'>,</span><span class='id identifier rubyid_v'>v</span><span class='op'>|</span> <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Miss: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_k'>k</span><span class='rbrace'>}</span><span class='tstring_content'>:<NA></span><span class='tstring_end'>"</span></span> <span class='rbrace'>}</span> <span class='rparen'>)</span>
|
127
|
+
|
128
|
+
<span class='comment'># Set some values.
|
129
|
+
</span><span class='id identifier rubyid_c'>c</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>foo</span><span class='tstring_end'>'</span></span> <span class='comment'># set 0 as 'foo'
|
130
|
+
</span><span class='id identifier rubyid_c'>c</span><span class='period'>.</span><span class='id identifier rubyid_put'>put</span><span class='lparen'>(</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>bar</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>foo</span><span class='tstring_end'>'</span></span> <span class='rparen'>)</span>
|
131
|
+
|
132
|
+
<span class='comment'># Get (or try to get) some values.
|
133
|
+
</span><span class='id identifier rubyid_a'>a</span> <span class='op'>=</span> <span class='id identifier rubyid_c'>c</span><span class='lbracket'>[</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>bar</span><span class='tstring_end'>'</span></span> <span class='rbracket'>]</span> <span class='comment'># hit, a == 'foo'
|
134
|
+
</span><span class='id identifier rubyid_b'>b</span> <span class='op'>=</span> <span class='id identifier rubyid_c'>c</span><span class='period'>.</span><span class='id identifier rubyid_get'>get</span><span class='lparen'>(</span> <span class='int'>0</span> <span class='rparen'>)</span> <span class='comment'># hit, b == 'foo'
|
135
|
+
</span><span class='id identifier rubyid_c'>c</span><span class='period'>.</span><span class='id identifier rubyid_get'>get</span><span class='lparen'>(</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>foo</span><span class='tstring_end'>'</span></span> <span class='rparen'>)</span> <span class='comment'># miss
|
136
|
+
</span><span class='id identifier rubyid_c'>c</span><span class='period'>.</span><span class='id identifier rubyid_get'>get</span><span class='lparen'>(</span> <span class='int'>2</span> <span class='rparen'>)</span> <span class='comment'># miss</span></code></pre>
|
137
|
+
|
138
|
+
<p>Produces:</p>
|
139
|
+
|
140
|
+
<pre class="code ruby"><code class="ruby">Hit: bar:foo
|
141
|
+
Found: bar:foo
|
142
|
+
Hit: 0:foo
|
143
|
+
Found: 0:foo
|
144
|
+
Miss: foo:<NA>
|
145
|
+
Miss: 2:<NA></code></pre>
|
146
|
+
|
147
|
+
|
148
|
+
</div>
|
149
|
+
</div>
|
150
|
+
<div class="tags">
|
151
|
+
|
152
|
+
|
153
|
+
</div><h2>Defined Under Namespace</h2>
|
154
|
+
<p class="children">
|
155
|
+
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
<strong class="classes">Classes:</strong> <span class='object_link'><a href="UniCache/CallbackError.html" title="UniCache::CallbackError (class)">CallbackError</a></span>, <span class='object_link'><a href="UniCache/Error.html" title="UniCache::Error (class)">Error</a></span>, <span class='object_link'><a href="UniCache/FetchError.html" title="UniCache::FetchError (class)">FetchError</a></span>, <span class='object_link'><a href="UniCache/LruEviction.html" title="UniCache::LruEviction (class)">LruEviction</a></span>, <span class='object_link'><a href="UniCache/RemoveError.html" title="UniCache::RemoveError (class)">RemoveError</a></span>, <span class='object_link'><a href="UniCache/SizeError.html" title="UniCache::SizeError (class)">SizeError</a></span>
|
160
|
+
|
161
|
+
|
162
|
+
</p>
|
163
|
+
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
<h2>Instance Attribute Summary <small>(<a href="#" class="summary_toggle">collapse</a>)</small></h2>
|
168
|
+
<ul class="summary">
|
169
|
+
|
170
|
+
<li class="public ">
|
171
|
+
<span class="summary_signature">
|
172
|
+
|
173
|
+
<a href="#lock-instance_method" title="#lock (instance method)">- (Object) <strong>lock</strong> </a>
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
</span>
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
|
182
|
+
<span class="note title readonly">readonly</span>
|
183
|
+
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
|
192
|
+
<span class="summary_desc"><div class='inline'>
|
193
|
+
<p>Access lock.</p>
|
194
|
+
</div></span>
|
195
|
+
|
196
|
+
</li>
|
197
|
+
|
198
|
+
|
199
|
+
<li class="public ">
|
200
|
+
<span class="summary_signature">
|
201
|
+
|
202
|
+
<a href="#size-instance_method" title="#size (instance method)">- (Object) <strong>size</strong> </a>
|
203
|
+
|
204
|
+
|
205
|
+
|
206
|
+
</span>
|
207
|
+
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
<span class="note title readonly">readonly</span>
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
<span class="summary_desc"><div class='inline'>
|
222
|
+
<p>Cache size.</p>
|
223
|
+
</div></span>
|
224
|
+
|
225
|
+
</li>
|
226
|
+
|
227
|
+
|
228
|
+
</ul>
|
229
|
+
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
|
234
|
+
<h2>
|
235
|
+
Instance Method Summary
|
236
|
+
<small>(<a href="#" class="summary_toggle">collapse</a>)</small>
|
237
|
+
</h2>
|
238
|
+
|
239
|
+
<ul class="summary">
|
240
|
+
|
241
|
+
<li class="public ">
|
242
|
+
<span class="summary_signature">
|
243
|
+
|
244
|
+
<a href="#%5B%5D-instance_method" title="#[] (instance method)">- (Object) <strong>[]</strong>(key) </a>
|
245
|
+
|
246
|
+
|
247
|
+
|
248
|
+
</span>
|
249
|
+
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
|
258
|
+
<span class="summary_desc"><div class='inline'>
|
259
|
+
<p>Get operator.</p>
|
260
|
+
</div></span>
|
261
|
+
|
262
|
+
</li>
|
263
|
+
|
264
|
+
|
265
|
+
<li class="public ">
|
266
|
+
<span class="summary_signature">
|
267
|
+
|
268
|
+
<a href="#%5B%5D%3D-instance_method" title="#[]= (instance method)">- (Object) <strong>[]=</strong>(key, value) </a>
|
269
|
+
|
270
|
+
|
271
|
+
|
272
|
+
</span>
|
273
|
+
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
|
282
|
+
<span class="summary_desc"><div class='inline'>
|
283
|
+
<p>Put operator.</p>
|
284
|
+
</div></span>
|
285
|
+
|
286
|
+
</li>
|
287
|
+
|
288
|
+
|
289
|
+
<li class="public ">
|
290
|
+
<span class="summary_signature">
|
291
|
+
|
292
|
+
<a href="#clear-instance_method" title="#clear (instance method)">- (Object) <strong>clear</strong> </a>
|
293
|
+
|
294
|
+
|
295
|
+
|
296
|
+
</span>
|
297
|
+
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
|
306
|
+
<span class="summary_desc"><div class='inline'>
|
307
|
+
<p>Clear all Cache entries.</p>
|
308
|
+
</div></span>
|
309
|
+
|
310
|
+
</li>
|
311
|
+
|
312
|
+
|
313
|
+
<li class="public ">
|
314
|
+
<span class="summary_signature">
|
315
|
+
|
316
|
+
<a href="#exist%3F-instance_method" title="#exist? (instance method)">- (Boolean) <strong>exist?</strong>(key) </a>
|
317
|
+
|
318
|
+
|
319
|
+
|
320
|
+
</span>
|
321
|
+
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
|
330
|
+
<span class="summary_desc"><div class='inline'>
|
331
|
+
<p>Get Cache entry existance by key (no effect to eviction).</p>
|
332
|
+
</div></span>
|
333
|
+
|
334
|
+
</li>
|
335
|
+
|
336
|
+
|
337
|
+
<li class="public ">
|
338
|
+
<span class="summary_signature">
|
339
|
+
|
340
|
+
<a href="#get-instance_method" title="#get (instance method)">- (Object) <strong>get</strong>(key) { ... }</a>
|
341
|
+
|
342
|
+
|
343
|
+
|
344
|
+
</span>
|
345
|
+
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
|
354
|
+
<span class="summary_desc"><div class='inline'>
|
355
|
+
<p>Get Cache entry by key or return nil if not in Cache.</p>
|
356
|
+
</div></span>
|
357
|
+
|
358
|
+
</li>
|
359
|
+
|
360
|
+
|
361
|
+
<li class="public ">
|
362
|
+
<span class="summary_signature">
|
363
|
+
|
364
|
+
<a href="#hash_get_op-instance_method" title="#hash_get_op (instance method)">- (Object) <strong>hash_get_op</strong> </a>
|
365
|
+
|
366
|
+
|
367
|
+
|
368
|
+
</span>
|
369
|
+
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
|
378
|
+
<span class="summary_desc"><div class='inline'></div></span>
|
379
|
+
|
380
|
+
</li>
|
381
|
+
|
382
|
+
|
383
|
+
<li class="public ">
|
384
|
+
<span class="summary_signature">
|
385
|
+
|
386
|
+
<a href="#hash_set_op-instance_method" title="#hash_set_op (instance method)">- (Object) <strong>hash_set_op</strong> </a>
|
387
|
+
|
388
|
+
|
389
|
+
|
390
|
+
</span>
|
391
|
+
|
392
|
+
|
393
|
+
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
|
398
|
+
|
399
|
+
|
400
|
+
<span class="summary_desc"><div class='inline'></div></span>
|
401
|
+
|
402
|
+
</li>
|
403
|
+
|
404
|
+
|
405
|
+
<li class="public ">
|
406
|
+
<span class="summary_signature">
|
407
|
+
|
408
|
+
<a href="#hash_store-instance_method" title="#hash_store (instance method)">- (Object) <strong>hash_store</strong> </a>
|
409
|
+
|
410
|
+
|
411
|
+
|
412
|
+
</span>
|
413
|
+
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
|
418
|
+
|
419
|
+
|
420
|
+
|
421
|
+
|
422
|
+
<span class="summary_desc"><div class='inline'></div></span>
|
423
|
+
|
424
|
+
</li>
|
425
|
+
|
426
|
+
|
427
|
+
<li class="public ">
|
428
|
+
<span class="summary_signature">
|
429
|
+
|
430
|
+
<a href="#initialize-instance_method" title="#initialize (instance method)">- (UniCache) <strong>initialize</strong>(size, evict = LruEviction.new) </a>
|
431
|
+
|
432
|
+
|
433
|
+
|
434
|
+
</span>
|
435
|
+
|
436
|
+
|
437
|
+
<span class="note title constructor">constructor</span>
|
438
|
+
|
439
|
+
|
440
|
+
|
441
|
+
|
442
|
+
|
443
|
+
|
444
|
+
|
445
|
+
|
446
|
+
<span class="summary_desc"><div class='inline'>
|
447
|
+
<p>Cache initialization.</p>
|
448
|
+
</div></span>
|
449
|
+
|
450
|
+
</li>
|
451
|
+
|
452
|
+
|
453
|
+
<li class="public ">
|
454
|
+
<span class="summary_signature">
|
455
|
+
|
456
|
+
<a href="#peek-instance_method" title="#peek (instance method)">- (Object) <strong>peek</strong>(key) </a>
|
457
|
+
|
458
|
+
|
459
|
+
|
460
|
+
</span>
|
461
|
+
|
462
|
+
|
463
|
+
|
464
|
+
|
465
|
+
|
466
|
+
|
467
|
+
|
468
|
+
|
469
|
+
|
470
|
+
<span class="summary_desc"><div class='inline'>
|
471
|
+
<p>Get Cache entry by key (no effect to eviction).</p>
|
472
|
+
</div></span>
|
473
|
+
|
474
|
+
</li>
|
475
|
+
|
476
|
+
|
477
|
+
<li class="public ">
|
478
|
+
<span class="summary_signature">
|
479
|
+
|
480
|
+
<a href="#put-instance_method" title="#put (instance method)">- (Object) <strong>put</strong>(key, value) </a>
|
481
|
+
|
482
|
+
|
483
|
+
|
484
|
+
</span>
|
485
|
+
|
486
|
+
|
487
|
+
|
488
|
+
|
489
|
+
|
490
|
+
|
491
|
+
|
492
|
+
|
493
|
+
|
494
|
+
<span class="summary_desc"><div class='inline'>
|
495
|
+
<p>Put new entry to the Cache.</p>
|
496
|
+
</div></span>
|
497
|
+
|
498
|
+
</li>
|
499
|
+
|
500
|
+
|
501
|
+
<li class="public ">
|
502
|
+
<span class="summary_signature">
|
503
|
+
|
504
|
+
<a href="#registerCallback-instance_method" title="#registerCallback (instance method)">- (Object) <strong>registerCallback</strong>(type, proc) </a>
|
505
|
+
|
506
|
+
|
507
|
+
|
508
|
+
</span>
|
509
|
+
|
510
|
+
|
511
|
+
|
512
|
+
|
513
|
+
|
514
|
+
|
515
|
+
|
516
|
+
|
517
|
+
|
518
|
+
<span class="summary_desc"><div class='inline'>
|
519
|
+
<p>Register a callback to be executed on Cache event.</p>
|
520
|
+
</div></span>
|
521
|
+
|
522
|
+
</li>
|
523
|
+
|
524
|
+
|
525
|
+
<li class="public ">
|
526
|
+
<span class="summary_signature">
|
527
|
+
|
528
|
+
<a href="#remove-instance_method" title="#remove (instance method)">- (Object) <strong>remove</strong>(key = nil) </a>
|
529
|
+
|
530
|
+
|
531
|
+
|
532
|
+
</span>
|
533
|
+
|
534
|
+
|
535
|
+
|
536
|
+
|
537
|
+
|
538
|
+
|
539
|
+
|
540
|
+
|
541
|
+
|
542
|
+
<span class="summary_desc"><div class='inline'>
|
543
|
+
<p>Remove oldest Cache entry (Least Recently Used) or given.</p>
|
544
|
+
</div></span>
|
545
|
+
|
546
|
+
</li>
|
547
|
+
|
548
|
+
|
549
|
+
<li class="public ">
|
550
|
+
<span class="summary_signature">
|
551
|
+
|
552
|
+
<a href="#removeCallback-instance_method" title="#removeCallback (instance method)">- (Object) <strong>removeCallback</strong>(type = nil) </a>
|
553
|
+
|
554
|
+
|
555
|
+
|
556
|
+
</span>
|
557
|
+
|
558
|
+
|
559
|
+
|
560
|
+
|
561
|
+
|
562
|
+
|
563
|
+
|
564
|
+
|
565
|
+
|
566
|
+
<span class="summary_desc"><div class='inline'>
|
567
|
+
<p>Remove all callbacks for type or all.</p>
|
568
|
+
</div></span>
|
569
|
+
|
570
|
+
</li>
|
571
|
+
|
572
|
+
|
573
|
+
<li class="public ">
|
574
|
+
<span class="summary_signature">
|
575
|
+
|
576
|
+
<a href="#resize-instance_method" title="#resize (instance method)">- (Object) <strong>resize</strong>(size) </a>
|
577
|
+
|
578
|
+
|
579
|
+
|
580
|
+
</span>
|
581
|
+
|
582
|
+
|
583
|
+
|
584
|
+
|
585
|
+
|
586
|
+
|
587
|
+
|
588
|
+
|
589
|
+
|
590
|
+
<span class="summary_desc"><div class='inline'>
|
591
|
+
<p>Resize the Cache.</p>
|
592
|
+
</div></span>
|
593
|
+
|
594
|
+
</li>
|
595
|
+
|
596
|
+
|
597
|
+
<li class="public ">
|
598
|
+
<span class="summary_signature">
|
599
|
+
|
600
|
+
<a href="#setEviction-instance_method" title="#setEviction (instance method)">- (Object) <strong>setEviction</strong>(evict) </a>
|
601
|
+
|
602
|
+
|
603
|
+
|
604
|
+
</span>
|
605
|
+
|
606
|
+
|
607
|
+
|
608
|
+
|
609
|
+
|
610
|
+
|
611
|
+
|
612
|
+
|
613
|
+
|
614
|
+
<span class="summary_desc"><div class='inline'>
|
615
|
+
<p>Set the eviction policy.</p>
|
616
|
+
</div></span>
|
617
|
+
|
618
|
+
</li>
|
619
|
+
|
620
|
+
|
621
|
+
<li class="public ">
|
622
|
+
<span class="summary_signature">
|
623
|
+
|
624
|
+
<a href="#store-instance_method" title="#store (instance method)">- (Object) <strong>store</strong> </a>
|
625
|
+
|
626
|
+
|
627
|
+
|
628
|
+
</span>
|
629
|
+
|
630
|
+
|
631
|
+
|
632
|
+
|
633
|
+
|
634
|
+
|
635
|
+
|
636
|
+
|
637
|
+
|
638
|
+
<span class="summary_desc"><div class='inline'>
|
639
|
+
<p>Dummy definition for "store" just for removal.</p>
|
640
|
+
</div></span>
|
641
|
+
|
642
|
+
</li>
|
643
|
+
|
644
|
+
|
645
|
+
</ul>
|
646
|
+
|
647
|
+
|
648
|
+
|
649
|
+
<div id="constructor_details" class="method_details_list">
|
650
|
+
<h2>Constructor Details</h2>
|
651
|
+
|
652
|
+
<div class="method_details first">
|
653
|
+
<h3 class="signature first" id="initialize-instance_method">
|
654
|
+
|
655
|
+
- (<tt><span class='object_link'><a href="" title="UniCache (class)">UniCache</a></span></tt>) <strong>initialize</strong>(size, evict = LruEviction.new)
|
656
|
+
|
657
|
+
|
658
|
+
|
659
|
+
|
660
|
+
|
661
|
+
</h3><div class="docstring">
|
662
|
+
<div class="discussion">
|
663
|
+
|
664
|
+
<p>Cache initialization.</p>
|
665
|
+
|
666
|
+
|
667
|
+
</div>
|
668
|
+
</div>
|
669
|
+
<div class="tags">
|
670
|
+
<p class="tag_title">Parameters:</p>
|
671
|
+
<ul class="param">
|
672
|
+
|
673
|
+
<li>
|
674
|
+
|
675
|
+
<span class='name'>size</span>
|
676
|
+
|
677
|
+
|
678
|
+
<span class='type'>(<tt>Integer</tt>)</span>
|
679
|
+
|
680
|
+
|
681
|
+
|
682
|
+
—
|
683
|
+
<div class='inline'>
|
684
|
+
<p>Cache size.</p>
|
685
|
+
</div>
|
686
|
+
|
687
|
+
</li>
|
688
|
+
|
689
|
+
<li>
|
690
|
+
|
691
|
+
<span class='name'>evict</span>
|
692
|
+
|
693
|
+
|
694
|
+
<span class='type'>(<tt>Object</tt>)</span>
|
695
|
+
|
696
|
+
|
697
|
+
<em class="default">(defaults to: <tt>LruEviction.new</tt>)</em>
|
698
|
+
|
699
|
+
|
700
|
+
—
|
701
|
+
<div class='inline'>
|
702
|
+
<p>Eviction policy.</p>
|
703
|
+
</div>
|
704
|
+
|
705
|
+
</li>
|
706
|
+
|
707
|
+
</ul>
|
708
|
+
|
709
|
+
|
710
|
+
</div><table class="source_code">
|
711
|
+
<tr>
|
712
|
+
<td>
|
713
|
+
<pre class="lines">
|
714
|
+
|
715
|
+
|
716
|
+
68
|
717
|
+
69
|
718
|
+
70
|
719
|
+
71
|
720
|
+
72
|
721
|
+
73
|
722
|
+
74
|
723
|
+
75
|
724
|
+
76
|
725
|
+
77
|
726
|
+
78
|
727
|
+
79
|
728
|
+
80
|
729
|
+
81
|
730
|
+
82
|
731
|
+
83
|
732
|
+
84
|
733
|
+
85
|
734
|
+
86
|
735
|
+
87
|
736
|
+
88
|
737
|
+
89</pre>
|
738
|
+
</td>
|
739
|
+
<td>
|
740
|
+
<pre class="code"><span class="info file"># File 'lib/unicache.rb', line 68</span>
|
741
|
+
|
742
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span> <span class='id identifier rubyid_size'>size</span><span class='comma'>,</span> <span class='id identifier rubyid_evict'>evict</span> <span class='op'>=</span> <span class='const'>LruEviction</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='rparen'>)</span>
|
743
|
+
<span class='kw'>super</span><span class='lparen'>(</span><span class='rparen'>)</span>
|
744
|
+
|
745
|
+
<span class='ivar'>@lock</span> <span class='op'>=</span> <span class='const'>Mutex</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
|
746
|
+
|
747
|
+
<span class='id identifier rubyid_resize'>resize</span><span class='lparen'>(</span> <span class='id identifier rubyid_size'>size</span> <span class='rparen'>)</span>
|
748
|
+
|
749
|
+
<span class='id identifier rubyid_setEviction'>setEviction</span><span class='lparen'>(</span> <span class='id identifier rubyid_evict'>evict</span> <span class='rparen'>)</span>
|
750
|
+
|
751
|
+
<span class='comment'># See: registerCallback.
|
752
|
+
</span> <span class='ivar'>@callbacks</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
|
753
|
+
|
754
|
+
<span class='ivar'>@callbackType</span> <span class='op'>=</span> <span class='lbracket'>[</span> <span class='symbol'>:getdata</span><span class='comma'>,</span>
|
755
|
+
<span class='symbol'>:add</span><span class='comma'>,</span> <span class='symbol'>:replace</span><span class='comma'>,</span> <span class='symbol'>:put</span><span class='comma'>,</span> <span class='symbol'>:overwrite</span><span class='comma'>,</span>
|
756
|
+
<span class='symbol'>:remove</span><span class='comma'>,</span> <span class='symbol'>:valueremove</span><span class='comma'>,</span> <span class='symbol'>:hit</span><span class='comma'>,</span> <span class='symbol'>:miss</span><span class='comma'>,</span>
|
757
|
+
<span class='symbol'>:peek</span> <span class='rbracket'>]</span>
|
758
|
+
|
759
|
+
<span class='ivar'>@callbackType</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_type'>type</span><span class='op'>|</span>
|
760
|
+
<span class='ivar'>@callbacks</span><span class='lbracket'>[</span> <span class='id identifier rubyid_type'>type</span> <span class='rbracket'>]</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
|
761
|
+
<span class='kw'>end</span>
|
762
|
+
|
763
|
+
<span class='kw'>end</span></pre>
|
764
|
+
</td>
|
765
|
+
</tr>
|
766
|
+
</table>
|
767
|
+
</div>
|
768
|
+
|
769
|
+
</div>
|
770
|
+
|
771
|
+
<div id="instance_attr_details" class="attr_details">
|
772
|
+
<h2>Instance Attribute Details</h2>
|
773
|
+
|
774
|
+
|
775
|
+
<span id=""></span>
|
776
|
+
<div class="method_details first">
|
777
|
+
<h3 class="signature first" id="lock-instance_method">
|
778
|
+
|
779
|
+
- (<tt>Object</tt>) <strong>lock</strong> <span class="extras">(readonly)</span>
|
780
|
+
|
781
|
+
|
782
|
+
|
783
|
+
|
784
|
+
|
785
|
+
</h3><div class="docstring">
|
786
|
+
<div class="discussion">
|
787
|
+
|
788
|
+
<p>Access lock.</p>
|
789
|
+
|
790
|
+
|
791
|
+
</div>
|
792
|
+
</div>
|
793
|
+
<div class="tags">
|
794
|
+
|
795
|
+
|
796
|
+
</div><table class="source_code">
|
797
|
+
<tr>
|
798
|
+
<td>
|
799
|
+
<pre class="lines">
|
800
|
+
|
801
|
+
|
802
|
+
62
|
803
|
+
63
|
804
|
+
64</pre>
|
805
|
+
</td>
|
806
|
+
<td>
|
807
|
+
<pre class="code"><span class="info file"># File 'lib/unicache.rb', line 62</span>
|
808
|
+
|
809
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_lock'>lock</span>
|
810
|
+
<span class='ivar'>@lock</span>
|
811
|
+
<span class='kw'>end</span></pre>
|
812
|
+
</td>
|
813
|
+
</tr>
|
814
|
+
</table>
|
815
|
+
</div>
|
816
|
+
|
817
|
+
|
818
|
+
<span id=""></span>
|
819
|
+
<div class="method_details ">
|
820
|
+
<h3 class="signature " id="size-instance_method">
|
821
|
+
|
822
|
+
- (<tt>Object</tt>) <strong>size</strong> <span class="extras">(readonly)</span>
|
823
|
+
|
824
|
+
|
825
|
+
|
826
|
+
|
827
|
+
|
828
|
+
</h3><div class="docstring">
|
829
|
+
<div class="discussion">
|
830
|
+
|
831
|
+
<p>Cache size.</p>
|
832
|
+
|
833
|
+
|
834
|
+
</div>
|
835
|
+
</div>
|
836
|
+
<div class="tags">
|
837
|
+
|
838
|
+
|
839
|
+
</div><table class="source_code">
|
840
|
+
<tr>
|
841
|
+
<td>
|
842
|
+
<pre class="lines">
|
843
|
+
|
844
|
+
|
845
|
+
59
|
846
|
+
60
|
847
|
+
61</pre>
|
848
|
+
</td>
|
849
|
+
<td>
|
850
|
+
<pre class="code"><span class="info file"># File 'lib/unicache.rb', line 59</span>
|
851
|
+
|
852
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_size'>size</span>
|
853
|
+
<span class='ivar'>@size</span>
|
854
|
+
<span class='kw'>end</span></pre>
|
855
|
+
</td>
|
856
|
+
</tr>
|
857
|
+
</table>
|
858
|
+
</div>
|
859
|
+
|
860
|
+
</div>
|
861
|
+
|
862
|
+
|
863
|
+
<div id="instance_method_details" class="method_details_list">
|
864
|
+
<h2>Instance Method Details</h2>
|
865
|
+
|
866
|
+
|
867
|
+
<div class="method_details first">
|
868
|
+
<h3 class="signature first" id="[]-instance_method">
|
869
|
+
|
870
|
+
- (<tt>Object</tt>) <strong>[]</strong>(key)
|
871
|
+
|
872
|
+
|
873
|
+
|
874
|
+
|
875
|
+
|
876
|
+
</h3><div class="docstring">
|
877
|
+
<div class="discussion">
|
878
|
+
|
879
|
+
<p>Get operator.</p>
|
880
|
+
|
881
|
+
|
882
|
+
</div>
|
883
|
+
</div>
|
884
|
+
<div class="tags">
|
885
|
+
|
886
|
+
|
887
|
+
</div><table class="source_code">
|
888
|
+
<tr>
|
889
|
+
<td>
|
890
|
+
<pre class="lines">
|
891
|
+
|
892
|
+
|
893
|
+
162
|
894
|
+
163
|
895
|
+
164</pre>
|
896
|
+
</td>
|
897
|
+
<td>
|
898
|
+
<pre class="code"><span class="info file"># File 'lib/unicache.rb', line 162</span>
|
899
|
+
|
900
|
+
<span class='kw'>def</span> <span class='op'>[]</span><span class='lparen'>(</span> <span class='id identifier rubyid_key'>key</span> <span class='rparen'>)</span>
|
901
|
+
<span class='id identifier rubyid_get'>get</span><span class='lparen'>(</span> <span class='id identifier rubyid_key'>key</span> <span class='rparen'>)</span>
|
902
|
+
<span class='kw'>end</span></pre>
|
903
|
+
</td>
|
904
|
+
</tr>
|
905
|
+
</table>
|
906
|
+
</div>
|
907
|
+
|
908
|
+
<div class="method_details ">
|
909
|
+
<h3 class="signature " id="[]=-instance_method">
|
910
|
+
|
911
|
+
- (<tt>Object</tt>) <strong>[]=</strong>(key, value)
|
912
|
+
|
913
|
+
|
914
|
+
|
915
|
+
|
916
|
+
|
917
|
+
</h3><div class="docstring">
|
918
|
+
<div class="discussion">
|
919
|
+
|
920
|
+
<p>Put operator.</p>
|
921
|
+
|
922
|
+
|
923
|
+
</div>
|
924
|
+
</div>
|
925
|
+
<div class="tags">
|
926
|
+
|
927
|
+
|
928
|
+
</div><table class="source_code">
|
929
|
+
<tr>
|
930
|
+
<td>
|
931
|
+
<pre class="lines">
|
932
|
+
|
933
|
+
|
934
|
+
137
|
935
|
+
138
|
936
|
+
139</pre>
|
937
|
+
</td>
|
938
|
+
<td>
|
939
|
+
<pre class="code"><span class="info file"># File 'lib/unicache.rb', line 137</span>
|
940
|
+
|
941
|
+
<span class='kw'>def</span> <span class='op'>[]=</span><span class='lparen'>(</span> <span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span> <span class='rparen'>)</span>
|
942
|
+
<span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_put'>put</span><span class='lparen'>(</span> <span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span> <span class='rparen'>)</span>
|
943
|
+
<span class='kw'>end</span></pre>
|
944
|
+
</td>
|
945
|
+
</tr>
|
946
|
+
</table>
|
947
|
+
</div>
|
948
|
+
|
949
|
+
<div class="method_details ">
|
950
|
+
<h3 class="signature " id="clear-instance_method">
|
951
|
+
|
952
|
+
- (<tt>Object</tt>) <strong>clear</strong>
|
953
|
+
|
954
|
+
|
955
|
+
|
956
|
+
|
957
|
+
|
958
|
+
</h3><div class="docstring">
|
959
|
+
<div class="discussion">
|
960
|
+
|
961
|
+
<p>Clear all Cache entries.</p>
|
962
|
+
|
963
|
+
|
964
|
+
</div>
|
965
|
+
</div>
|
966
|
+
<div class="tags">
|
967
|
+
|
968
|
+
|
969
|
+
</div><table class="source_code">
|
970
|
+
<tr>
|
971
|
+
<td>
|
972
|
+
<pre class="lines">
|
973
|
+
|
974
|
+
|
975
|
+
287
|
976
|
+
288
|
977
|
+
289
|
978
|
+
290
|
979
|
+
291
|
980
|
+
292
|
981
|
+
293
|
982
|
+
294</pre>
|
983
|
+
</td>
|
984
|
+
<td>
|
985
|
+
<pre class="code"><span class="info file"># File 'lib/unicache.rb', line 287</span>
|
986
|
+
|
987
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_clear'>clear</span>
|
988
|
+
<span class='ivar'>@lock</span><span class='period'>.</span><span class='id identifier rubyid_lock'>lock</span>
|
989
|
+
<span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_k'>k</span><span class='comma'>,</span><span class='id identifier rubyid_v'>v</span><span class='op'>|</span>
|
990
|
+
<span class='id identifier rubyid_removeEntry'>removeEntry</span><span class='lparen'>(</span> <span class='id identifier rubyid_k'>k</span> <span class='rparen'>)</span>
|
991
|
+
<span class='kw'>end</span>
|
992
|
+
<span class='ivar'>@evict</span><span class='period'>.</span><span class='id identifier rubyid_clear'>clear</span>
|
993
|
+
<span class='ivar'>@lock</span><span class='period'>.</span><span class='id identifier rubyid_unlock'>unlock</span>
|
994
|
+
<span class='kw'>end</span></pre>
|
995
|
+
</td>
|
996
|
+
</tr>
|
997
|
+
</table>
|
998
|
+
</div>
|
999
|
+
|
1000
|
+
<div class="method_details ">
|
1001
|
+
<h3 class="signature " id="exist?-instance_method">
|
1002
|
+
|
1003
|
+
- (<tt>Boolean</tt>) <strong>exist?</strong>(key)
|
1004
|
+
|
1005
|
+
|
1006
|
+
|
1007
|
+
|
1008
|
+
|
1009
|
+
</h3><div class="docstring">
|
1010
|
+
<div class="discussion">
|
1011
|
+
|
1012
|
+
<p>Get Cache entry existance by key (no effect to eviction). Uses "peek", i.e.
|
1013
|
+
peek CB is run.</p>
|
1014
|
+
|
1015
|
+
|
1016
|
+
</div>
|
1017
|
+
</div>
|
1018
|
+
<div class="tags">
|
1019
|
+
<p class="tag_title">Parameters:</p>
|
1020
|
+
<ul class="param">
|
1021
|
+
|
1022
|
+
<li>
|
1023
|
+
|
1024
|
+
<span class='name'>key</span>
|
1025
|
+
|
1026
|
+
|
1027
|
+
<span class='type'>(<tt>Object</tt>)</span>
|
1028
|
+
|
1029
|
+
|
1030
|
+
|
1031
|
+
—
|
1032
|
+
<div class='inline'>
|
1033
|
+
<p>Entry key or tag.</p>
|
1034
|
+
</div>
|
1035
|
+
|
1036
|
+
</li>
|
1037
|
+
|
1038
|
+
</ul>
|
1039
|
+
|
1040
|
+
<p class="tag_title">Returns:</p>
|
1041
|
+
<ul class="return">
|
1042
|
+
|
1043
|
+
<li>
|
1044
|
+
|
1045
|
+
|
1046
|
+
<span class='type'>(<tt>Boolean</tt>)</span>
|
1047
|
+
|
1048
|
+
|
1049
|
+
|
1050
|
+
</li>
|
1051
|
+
|
1052
|
+
</ul>
|
1053
|
+
|
1054
|
+
</div><table class="source_code">
|
1055
|
+
<tr>
|
1056
|
+
<td>
|
1057
|
+
<pre class="lines">
|
1058
|
+
|
1059
|
+
|
1060
|
+
180
|
1061
|
+
181
|
1062
|
+
182
|
1063
|
+
183
|
1064
|
+
184
|
1065
|
+
185
|
1066
|
+
186</pre>
|
1067
|
+
</td>
|
1068
|
+
<td>
|
1069
|
+
<pre class="code"><span class="info file"># File 'lib/unicache.rb', line 180</span>
|
1070
|
+
|
1071
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_exist?'>exist?</span><span class='lparen'>(</span> <span class='id identifier rubyid_key'>key</span> <span class='rparen'>)</span>
|
1072
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_peek'>peek</span><span class='lparen'>(</span> <span class='id identifier rubyid_key'>key</span> <span class='rparen'>)</span>
|
1073
|
+
<span class='kw'>true</span>
|
1074
|
+
<span class='kw'>else</span>
|
1075
|
+
<span class='kw'>false</span>
|
1076
|
+
<span class='kw'>end</span>
|
1077
|
+
<span class='kw'>end</span></pre>
|
1078
|
+
</td>
|
1079
|
+
</tr>
|
1080
|
+
</table>
|
1081
|
+
</div>
|
1082
|
+
|
1083
|
+
<div class="method_details ">
|
1084
|
+
<h3 class="signature " id="get-instance_method">
|
1085
|
+
|
1086
|
+
- (<tt>Object</tt>) <strong>get</strong>(key) { ... }
|
1087
|
+
|
1088
|
+
|
1089
|
+
|
1090
|
+
|
1091
|
+
|
1092
|
+
</h3><div class="docstring">
|
1093
|
+
<div class="discussion">
|
1094
|
+
|
1095
|
+
<p>Get Cache entry by key or return nil if not in Cache.</p>
|
1096
|
+
|
1097
|
+
<p>If block is provided, it is run under UniCache lock and will protect the
|
1098
|
+
used data from being removed (concurrently).</p>
|
1099
|
+
|
1100
|
+
<p>If ":getdata" callback is defined, it is used to get data. Data is always
|
1101
|
+
used, also when nil. UniCache lock is released before callback is called.</p>
|
1102
|
+
|
1103
|
+
|
1104
|
+
</div>
|
1105
|
+
</div>
|
1106
|
+
<div class="tags">
|
1107
|
+
<p class="tag_title">Parameters:</p>
|
1108
|
+
<ul class="param">
|
1109
|
+
|
1110
|
+
<li>
|
1111
|
+
|
1112
|
+
<span class='name'>key</span>
|
1113
|
+
|
1114
|
+
|
1115
|
+
<span class='type'>(<tt>Object</tt>)</span>
|
1116
|
+
|
1117
|
+
|
1118
|
+
|
1119
|
+
—
|
1120
|
+
<div class='inline'>
|
1121
|
+
<p>Key (or tag) of the Cache entry.</p>
|
1122
|
+
</div>
|
1123
|
+
|
1124
|
+
</li>
|
1125
|
+
|
1126
|
+
</ul>
|
1127
|
+
|
1128
|
+
<p class="tag_title">Yields:</p>
|
1129
|
+
<ul class="yield">
|
1130
|
+
|
1131
|
+
<li>
|
1132
|
+
|
1133
|
+
|
1134
|
+
<span class='type'></span>
|
1135
|
+
|
1136
|
+
|
1137
|
+
|
1138
|
+
|
1139
|
+
<div class='inline'>
|
1140
|
+
<p>Procedure to fetch the data.</p>
|
1141
|
+
</div>
|
1142
|
+
|
1143
|
+
</li>
|
1144
|
+
|
1145
|
+
</ul>
|
1146
|
+
|
1147
|
+
</div><table class="source_code">
|
1148
|
+
<tr>
|
1149
|
+
<td>
|
1150
|
+
<pre class="lines">
|
1151
|
+
|
1152
|
+
|
1153
|
+
153
|
1154
|
+
154
|
1155
|
+
155
|
1156
|
+
156
|
1157
|
+
157
|
1158
|
+
158</pre>
|
1159
|
+
</td>
|
1160
|
+
<td>
|
1161
|
+
<pre class="code"><span class="info file"># File 'lib/unicache.rb', line 153</span>
|
1162
|
+
|
1163
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_get'>get</span><span class='lparen'>(</span> <span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_blk'>blk</span> <span class='rparen'>)</span>
|
1164
|
+
<span class='ivar'>@lock</span><span class='period'>.</span><span class='id identifier rubyid_lock'>lock</span>
|
1165
|
+
<span class='id identifier rubyid_ret'>ret</span> <span class='op'>=</span> <span class='id identifier rubyid__get'>_get</span><span class='lparen'>(</span> <span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_blk'>blk</span> <span class='rparen'>)</span>
|
1166
|
+
<span class='ivar'>@lock</span><span class='period'>.</span><span class='id identifier rubyid_unlock'>unlock</span>
|
1167
|
+
<span class='id identifier rubyid_ret'>ret</span>
|
1168
|
+
<span class='kw'>end</span></pre>
|
1169
|
+
</td>
|
1170
|
+
</tr>
|
1171
|
+
</table>
|
1172
|
+
</div>
|
1173
|
+
|
1174
|
+
<div class="method_details ">
|
1175
|
+
<h3 class="signature " id="hash_get_op-instance_method">
|
1176
|
+
|
1177
|
+
- (<tt>Object</tt>) <strong>hash_get_op</strong>
|
1178
|
+
|
1179
|
+
|
1180
|
+
|
1181
|
+
|
1182
|
+
|
1183
|
+
</h3><table class="source_code">
|
1184
|
+
<tr>
|
1185
|
+
<td>
|
1186
|
+
<pre class="lines">
|
1187
|
+
|
1188
|
+
|
1189
|
+
101</pre>
|
1190
|
+
</td>
|
1191
|
+
<td>
|
1192
|
+
<pre class="code"><span class="info file"># File 'lib/unicache.rb', line 101</span>
|
1193
|
+
|
1194
|
+
<span class='kw'>alias</span> <span class='symbol'>:hash_get_op</span> <span class='symbol'>:[]</span></pre>
|
1195
|
+
</td>
|
1196
|
+
</tr>
|
1197
|
+
</table>
|
1198
|
+
</div>
|
1199
|
+
|
1200
|
+
<div class="method_details ">
|
1201
|
+
<h3 class="signature " id="hash_set_op-instance_method">
|
1202
|
+
|
1203
|
+
- (<tt>Object</tt>) <strong>hash_set_op</strong>
|
1204
|
+
|
1205
|
+
|
1206
|
+
|
1207
|
+
|
1208
|
+
|
1209
|
+
</h3><table class="source_code">
|
1210
|
+
<tr>
|
1211
|
+
<td>
|
1212
|
+
<pre class="lines">
|
1213
|
+
|
1214
|
+
|
1215
|
+
100</pre>
|
1216
|
+
</td>
|
1217
|
+
<td>
|
1218
|
+
<pre class="code"><span class="info file"># File 'lib/unicache.rb', line 100</span>
|
1219
|
+
|
1220
|
+
<span class='kw'>alias</span> <span class='symbol'>:hash_set_op</span> <span class='symbol'>:[]=</span></pre>
|
1221
|
+
</td>
|
1222
|
+
</tr>
|
1223
|
+
</table>
|
1224
|
+
</div>
|
1225
|
+
|
1226
|
+
<div class="method_details ">
|
1227
|
+
<h3 class="signature " id="hash_store-instance_method">
|
1228
|
+
|
1229
|
+
- (<tt>Object</tt>) <strong>hash_store</strong>
|
1230
|
+
|
1231
|
+
|
1232
|
+
|
1233
|
+
|
1234
|
+
|
1235
|
+
</h3><table class="source_code">
|
1236
|
+
<tr>
|
1237
|
+
<td>
|
1238
|
+
<pre class="lines">
|
1239
|
+
|
1240
|
+
|
1241
|
+
103</pre>
|
1242
|
+
</td>
|
1243
|
+
<td>
|
1244
|
+
<pre class="code"><span class="info file"># File 'lib/unicache.rb', line 103</span>
|
1245
|
+
|
1246
|
+
<span class='kw'>alias</span> <span class='symbol'>:hash_store</span> <span class='symbol'>:store</span></pre>
|
1247
|
+
</td>
|
1248
|
+
</tr>
|
1249
|
+
</table>
|
1250
|
+
</div>
|
1251
|
+
|
1252
|
+
<div class="method_details ">
|
1253
|
+
<h3 class="signature " id="peek-instance_method">
|
1254
|
+
|
1255
|
+
- (<tt>Object</tt>) <strong>peek</strong>(key)
|
1256
|
+
|
1257
|
+
|
1258
|
+
|
1259
|
+
|
1260
|
+
|
1261
|
+
</h3><div class="docstring">
|
1262
|
+
<div class="discussion">
|
1263
|
+
|
1264
|
+
<p>Get Cache entry by key (no effect to eviction).</p>
|
1265
|
+
|
1266
|
+
|
1267
|
+
</div>
|
1268
|
+
</div>
|
1269
|
+
<div class="tags">
|
1270
|
+
<p class="tag_title">Parameters:</p>
|
1271
|
+
<ul class="param">
|
1272
|
+
|
1273
|
+
<li>
|
1274
|
+
|
1275
|
+
<span class='name'>key</span>
|
1276
|
+
|
1277
|
+
|
1278
|
+
<span class='type'>(<tt>Object</tt>)</span>
|
1279
|
+
|
1280
|
+
|
1281
|
+
|
1282
|
+
—
|
1283
|
+
<div class='inline'>
|
1284
|
+
<p>Entry key or tag.</p>
|
1285
|
+
</div>
|
1286
|
+
|
1287
|
+
</li>
|
1288
|
+
|
1289
|
+
</ul>
|
1290
|
+
|
1291
|
+
|
1292
|
+
</div><table class="source_code">
|
1293
|
+
<tr>
|
1294
|
+
<td>
|
1295
|
+
<pre class="lines">
|
1296
|
+
|
1297
|
+
|
1298
|
+
170
|
1299
|
+
171
|
1300
|
+
172
|
1301
|
+
173</pre>
|
1302
|
+
</td>
|
1303
|
+
<td>
|
1304
|
+
<pre class="code"><span class="info file"># File 'lib/unicache.rb', line 170</span>
|
1305
|
+
|
1306
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_peek'>peek</span><span class='lparen'>(</span> <span class='id identifier rubyid_key'>key</span> <span class='rparen'>)</span>
|
1307
|
+
<span class='id identifier rubyid_runCallbacks'>runCallbacks</span><span class='lparen'>(</span> <span class='symbol'>:peek</span><span class='comma'>,</span> <span class='id identifier rubyid_key'>key</span> <span class='rparen'>)</span>
|
1308
|
+
<span class='id identifier rubyid_hash_fetch'>hash_fetch</span><span class='lparen'>(</span> <span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='kw'>nil</span> <span class='rparen'>)</span>
|
1309
|
+
<span class='kw'>end</span></pre>
|
1310
|
+
</td>
|
1311
|
+
</tr>
|
1312
|
+
</table>
|
1313
|
+
</div>
|
1314
|
+
|
1315
|
+
<div class="method_details ">
|
1316
|
+
<h3 class="signature " id="put-instance_method">
|
1317
|
+
|
1318
|
+
- (<tt>Object</tt>) <strong>put</strong>(key, value)
|
1319
|
+
|
1320
|
+
|
1321
|
+
|
1322
|
+
|
1323
|
+
|
1324
|
+
</h3><div class="docstring">
|
1325
|
+
<div class="discussion">
|
1326
|
+
|
1327
|
+
<p>Put new entry to the Cache. Make space for the new entry if needed.</p>
|
1328
|
+
|
1329
|
+
|
1330
|
+
</div>
|
1331
|
+
</div>
|
1332
|
+
<div class="tags">
|
1333
|
+
<p class="tag_title">Parameters:</p>
|
1334
|
+
<ul class="param">
|
1335
|
+
|
1336
|
+
<li>
|
1337
|
+
|
1338
|
+
<span class='name'>key</span>
|
1339
|
+
|
1340
|
+
|
1341
|
+
<span class='type'>(<tt>Object</tt>)</span>
|
1342
|
+
|
1343
|
+
|
1344
|
+
|
1345
|
+
—
|
1346
|
+
<div class='inline'>
|
1347
|
+
<p>Key (or tag) of the Cache entry.</p>
|
1348
|
+
</div>
|
1349
|
+
|
1350
|
+
</li>
|
1351
|
+
|
1352
|
+
<li>
|
1353
|
+
|
1354
|
+
<span class='name'>value</span>
|
1355
|
+
|
1356
|
+
|
1357
|
+
<span class='type'>(<tt>Object</tt>)</span>
|
1358
|
+
|
1359
|
+
|
1360
|
+
|
1361
|
+
—
|
1362
|
+
<div class='inline'>
|
1363
|
+
<p>Value of the Cache entry.</p>
|
1364
|
+
</div>
|
1365
|
+
|
1366
|
+
</li>
|
1367
|
+
|
1368
|
+
</ul>
|
1369
|
+
|
1370
|
+
|
1371
|
+
</div><table class="source_code">
|
1372
|
+
<tr>
|
1373
|
+
<td>
|
1374
|
+
<pre class="lines">
|
1375
|
+
|
1376
|
+
|
1377
|
+
128
|
1378
|
+
129
|
1379
|
+
130
|
1380
|
+
131
|
1381
|
+
132
|
1382
|
+
133</pre>
|
1383
|
+
</td>
|
1384
|
+
<td>
|
1385
|
+
<pre class="code"><span class="info file"># File 'lib/unicache.rb', line 128</span>
|
1386
|
+
|
1387
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_put'>put</span><span class='lparen'>(</span> <span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span> <span class='rparen'>)</span>
|
1388
|
+
<span class='ivar'>@lock</span><span class='period'>.</span><span class='id identifier rubyid_lock'>lock</span>
|
1389
|
+
<span class='id identifier rubyid_ret'>ret</span> <span class='op'>=</span> <span class='id identifier rubyid__put'>_put</span><span class='lparen'>(</span> <span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span> <span class='rparen'>)</span>
|
1390
|
+
<span class='ivar'>@lock</span><span class='period'>.</span><span class='id identifier rubyid_unlock'>unlock</span>
|
1391
|
+
<span class='id identifier rubyid_ret'>ret</span>
|
1392
|
+
<span class='kw'>end</span></pre>
|
1393
|
+
</td>
|
1394
|
+
</tr>
|
1395
|
+
</table>
|
1396
|
+
</div>
|
1397
|
+
|
1398
|
+
<div class="method_details ">
|
1399
|
+
<h3 class="signature " id="registerCallback-instance_method">
|
1400
|
+
|
1401
|
+
- (<tt>Object</tt>) <strong>registerCallback</strong>(type, proc)
|
1402
|
+
|
1403
|
+
|
1404
|
+
|
1405
|
+
|
1406
|
+
|
1407
|
+
</h3><div class="docstring">
|
1408
|
+
<div class="discussion">
|
1409
|
+
|
1410
|
+
<p>Register a callback to be executed on Cache event.</p>
|
1411
|
+
|
1412
|
+
<p>Possible events:</p>
|
1413
|
+
<dl class="rdoc-list"><dt>getdata</dt>
|
1414
|
+
<dd>
|
1415
|
+
<p>Data not found in cache, callback is used to fetch it. Data is always added
|
1416
|
+
to cache unless an exception is raised. Also all retrys should be captured
|
1417
|
+
into ":getdata". <key,value> from request.</p>
|
1418
|
+
</dd><dt>add</dt>
|
1419
|
+
<dd>
|
1420
|
+
<p>Item is added to Cache without anything being replaced. <key,value>
|
1421
|
+
from request.</p>
|
1422
|
+
</dd><dt>replace</dt>
|
1423
|
+
<dd>
|
1424
|
+
<p>Item is added to Cache and another item is removed. <key,value> is
|
1425
|
+
evicted entry.</p>
|
1426
|
+
</dd><dt>put</dt>
|
1427
|
+
<dd>
|
1428
|
+
<p>Item is added to Cache. Cache conditions has no effect i.e. always run for
|
1429
|
+
"put". <key,value> from request.</p>
|
1430
|
+
</dd><dt>overwrite</dt>
|
1431
|
+
<dd>
|
1432
|
+
<p>Existing entry value is replaced by new item value. <key,value> from
|
1433
|
+
request.</p>
|
1434
|
+
</dd><dt>remove</dt>
|
1435
|
+
<dd>
|
1436
|
+
<p>Entry is deleted from Cache.</p>
|
1437
|
+
</dd><dt>valueremove</dt>
|
1438
|
+
<dd>
|
1439
|
+
<p>Entry value is removed (remove or overwrite). <key,value> from old
|
1440
|
+
entry.</p>
|
1441
|
+
</dd><dt>hit</dt>
|
1442
|
+
<dd>
|
1443
|
+
<p>Entry is found in Cache. <key,value> from cache.</p>
|
1444
|
+
</dd><dt>miss</dt>
|
1445
|
+
<dd>
|
1446
|
+
<p>Entry is not found in Cache. <key> from request.</p>
|
1447
|
+
</dd><dt>peek</dt>
|
1448
|
+
<dd>
|
1449
|
+
<p>Cache peek. <key,value> from request.</p>
|
1450
|
+
</dd></dl>
|
1451
|
+
|
1452
|
+
<p>Example:</p>
|
1453
|
+
|
1454
|
+
<pre class="code ruby"><code class="ruby">registerCallback( :add,
|
1455
|
+
Proc.new do |k,v,o| puts "Key: #{k} with value #{v} added" end</code></pre>
|
1456
|
+
|
1457
|
+
|
1458
|
+
</div>
|
1459
|
+
</div>
|
1460
|
+
<div class="tags">
|
1461
|
+
<p class="tag_title">Parameters:</p>
|
1462
|
+
<ul class="param">
|
1463
|
+
|
1464
|
+
<li>
|
1465
|
+
|
1466
|
+
<span class='name'>type</span>
|
1467
|
+
|
1468
|
+
|
1469
|
+
<span class='type'>(<tt>Symbol</tt>)</span>
|
1470
|
+
|
1471
|
+
|
1472
|
+
|
1473
|
+
—
|
1474
|
+
<div class='inline'>
|
1475
|
+
<p>Callback event.</p>
|
1476
|
+
</div>
|
1477
|
+
|
1478
|
+
</li>
|
1479
|
+
|
1480
|
+
<li>
|
1481
|
+
|
1482
|
+
<span class='name'>proc</span>
|
1483
|
+
|
1484
|
+
|
1485
|
+
<span class='type'>(<tt>Proc</tt>)</span>
|
1486
|
+
|
1487
|
+
|
1488
|
+
|
1489
|
+
—
|
1490
|
+
<div class='inline'>
|
1491
|
+
<p>Callback called with args: <key>, <value>, <self>.</p>
|
1492
|
+
</div>
|
1493
|
+
|
1494
|
+
</li>
|
1495
|
+
|
1496
|
+
</ul>
|
1497
|
+
|
1498
|
+
|
1499
|
+
</div><table class="source_code">
|
1500
|
+
<tr>
|
1501
|
+
<td>
|
1502
|
+
<pre class="lines">
|
1503
|
+
|
1504
|
+
|
1505
|
+
263
|
1506
|
+
264
|
1507
|
+
265
|
1508
|
+
266
|
1509
|
+
267
|
1510
|
+
268
|
1511
|
+
269</pre>
|
1512
|
+
</td>
|
1513
|
+
<td>
|
1514
|
+
<pre class="code"><span class="info file"># File 'lib/unicache.rb', line 263</span>
|
1515
|
+
|
1516
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_registerCallback'>registerCallback</span><span class='lparen'>(</span> <span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='id identifier rubyid_proc'>proc</span> <span class='rparen'>)</span>
|
1517
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_proc'>proc</span><span class='period'>.</span><span class='id identifier rubyid_kind_of?'>kind_of?</span><span class='lparen'>(</span> <span class='const'>Proc</span> <span class='rparen'>)</span> <span class='op'>&&</span> <span class='ivar'>@callbackType</span><span class='period'>.</span><span class='id identifier rubyid_index'>index</span><span class='lparen'>(</span> <span class='id identifier rubyid_type'>type</span> <span class='rparen'>)</span>
|
1518
|
+
<span class='ivar'>@callbacks</span><span class='lbracket'>[</span> <span class='id identifier rubyid_type'>type</span> <span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_push'>push</span> <span class='id identifier rubyid_proc'>proc</span>
|
1519
|
+
<span class='kw'>else</span>
|
1520
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>CallbackError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>UniCache: Trying to register invalid callback...</span><span class='tstring_end'>"</span></span>
|
1521
|
+
<span class='kw'>end</span>
|
1522
|
+
<span class='kw'>end</span></pre>
|
1523
|
+
</td>
|
1524
|
+
</tr>
|
1525
|
+
</table>
|
1526
|
+
</div>
|
1527
|
+
|
1528
|
+
<div class="method_details ">
|
1529
|
+
<h3 class="signature " id="remove-instance_method">
|
1530
|
+
|
1531
|
+
- (<tt>Object</tt>) <strong>remove</strong>(key = nil)
|
1532
|
+
|
1533
|
+
|
1534
|
+
|
1535
|
+
|
1536
|
+
|
1537
|
+
</h3><div class="docstring">
|
1538
|
+
<div class="discussion">
|
1539
|
+
|
1540
|
+
<p>Remove oldest Cache entry (Least Recently Used) or given.</p>
|
1541
|
+
|
1542
|
+
|
1543
|
+
</div>
|
1544
|
+
</div>
|
1545
|
+
<div class="tags">
|
1546
|
+
<p class="tag_title">Parameters:</p>
|
1547
|
+
<ul class="param">
|
1548
|
+
|
1549
|
+
<li>
|
1550
|
+
|
1551
|
+
<span class='name'>key</span>
|
1552
|
+
|
1553
|
+
|
1554
|
+
<span class='type'>(<tt>Object</tt>)</span>
|
1555
|
+
|
1556
|
+
|
1557
|
+
<em class="default">(defaults to: <tt>nil</tt>)</em>
|
1558
|
+
|
1559
|
+
|
1560
|
+
—
|
1561
|
+
<div class='inline'>
|
1562
|
+
<p>Key to remove.</p>
|
1563
|
+
</div>
|
1564
|
+
|
1565
|
+
</li>
|
1566
|
+
|
1567
|
+
</ul>
|
1568
|
+
|
1569
|
+
<p class="tag_title">Returns:</p>
|
1570
|
+
<ul class="return">
|
1571
|
+
|
1572
|
+
<li>
|
1573
|
+
|
1574
|
+
|
1575
|
+
<span class='type'>(<tt>Object</tt>, <tt>Object</tt>)</span>
|
1576
|
+
|
1577
|
+
|
1578
|
+
|
1579
|
+
—
|
1580
|
+
<div class='inline'>
|
1581
|
+
<p>Key/value pair removed or nil if no entries.</p>
|
1582
|
+
</div>
|
1583
|
+
|
1584
|
+
</li>
|
1585
|
+
|
1586
|
+
</ul>
|
1587
|
+
|
1588
|
+
</div><table class="source_code">
|
1589
|
+
<tr>
|
1590
|
+
<td>
|
1591
|
+
<pre class="lines">
|
1592
|
+
|
1593
|
+
|
1594
|
+
193
|
1595
|
+
194
|
1596
|
+
195
|
1597
|
+
196
|
1598
|
+
197
|
1599
|
+
198</pre>
|
1600
|
+
</td>
|
1601
|
+
<td>
|
1602
|
+
<pre class="code"><span class="info file"># File 'lib/unicache.rb', line 193</span>
|
1603
|
+
|
1604
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_remove'>remove</span><span class='lparen'>(</span> <span class='id identifier rubyid_key'>key</span> <span class='op'>=</span> <span class='kw'>nil</span> <span class='rparen'>)</span>
|
1605
|
+
<span class='ivar'>@lock</span><span class='period'>.</span><span class='id identifier rubyid_lock'>lock</span>
|
1606
|
+
<span class='id identifier rubyid_ret'>ret</span> <span class='op'>=</span> <span class='id identifier rubyid__remove'>_remove</span><span class='lparen'>(</span> <span class='id identifier rubyid_key'>key</span> <span class='rparen'>)</span>
|
1607
|
+
<span class='ivar'>@lock</span><span class='period'>.</span><span class='id identifier rubyid_unlock'>unlock</span>
|
1608
|
+
<span class='id identifier rubyid_ret'>ret</span>
|
1609
|
+
<span class='kw'>end</span></pre>
|
1610
|
+
</td>
|
1611
|
+
</tr>
|
1612
|
+
</table>
|
1613
|
+
</div>
|
1614
|
+
|
1615
|
+
<div class="method_details ">
|
1616
|
+
<h3 class="signature " id="removeCallback-instance_method">
|
1617
|
+
|
1618
|
+
- (<tt>Object</tt>) <strong>removeCallback</strong>(type = nil)
|
1619
|
+
|
1620
|
+
|
1621
|
+
|
1622
|
+
|
1623
|
+
|
1624
|
+
</h3><div class="docstring">
|
1625
|
+
<div class="discussion">
|
1626
|
+
|
1627
|
+
<p>Remove all callbacks for type or all.</p>
|
1628
|
+
|
1629
|
+
|
1630
|
+
</div>
|
1631
|
+
</div>
|
1632
|
+
<div class="tags">
|
1633
|
+
<p class="tag_title">Parameters:</p>
|
1634
|
+
<ul class="param">
|
1635
|
+
|
1636
|
+
<li>
|
1637
|
+
|
1638
|
+
<span class='name'>type</span>
|
1639
|
+
|
1640
|
+
|
1641
|
+
<span class='type'>(<tt>Symbol</tt>)</span>
|
1642
|
+
|
1643
|
+
|
1644
|
+
<em class="default">(defaults to: <tt>nil</tt>)</em>
|
1645
|
+
|
1646
|
+
|
1647
|
+
—
|
1648
|
+
<div class='inline'>
|
1649
|
+
<p>Remove callback by type.</p>
|
1650
|
+
</div>
|
1651
|
+
|
1652
|
+
</li>
|
1653
|
+
|
1654
|
+
</ul>
|
1655
|
+
|
1656
|
+
|
1657
|
+
</div><table class="source_code">
|
1658
|
+
<tr>
|
1659
|
+
<td>
|
1660
|
+
<pre class="lines">
|
1661
|
+
|
1662
|
+
|
1663
|
+
275
|
1664
|
+
276
|
1665
|
+
277
|
1666
|
+
278
|
1667
|
+
279
|
1668
|
+
280
|
1669
|
+
281
|
1670
|
+
282
|
1671
|
+
283</pre>
|
1672
|
+
</td>
|
1673
|
+
<td>
|
1674
|
+
<pre class="code"><span class="info file"># File 'lib/unicache.rb', line 275</span>
|
1675
|
+
|
1676
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_removeCallback'>removeCallback</span><span class='lparen'>(</span> <span class='id identifier rubyid_type'>type</span> <span class='op'>=</span> <span class='kw'>nil</span> <span class='rparen'>)</span>
|
1677
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_type'>type</span>
|
1678
|
+
<span class='ivar'>@callbacks</span><span class='lbracket'>[</span> <span class='id identifier rubyid_type'>type</span> <span class='rbracket'>]</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
|
1679
|
+
<span class='kw'>else</span>
|
1680
|
+
<span class='ivar'>@callbackType</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_type'>type</span><span class='op'>|</span>
|
1681
|
+
<span class='ivar'>@callbacks</span><span class='lbracket'>[</span> <span class='id identifier rubyid_type'>type</span> <span class='rbracket'>]</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
|
1682
|
+
<span class='kw'>end</span>
|
1683
|
+
<span class='kw'>end</span>
|
1684
|
+
<span class='kw'>end</span></pre>
|
1685
|
+
</td>
|
1686
|
+
</tr>
|
1687
|
+
</table>
|
1688
|
+
</div>
|
1689
|
+
|
1690
|
+
<div class="method_details ">
|
1691
|
+
<h3 class="signature " id="resize-instance_method">
|
1692
|
+
|
1693
|
+
- (<tt>Object</tt>) <strong>resize</strong>(size)
|
1694
|
+
|
1695
|
+
|
1696
|
+
|
1697
|
+
|
1698
|
+
|
1699
|
+
</h3><div class="docstring">
|
1700
|
+
<div class="discussion">
|
1701
|
+
|
1702
|
+
<p>Resize the Cache.</p>
|
1703
|
+
|
1704
|
+
|
1705
|
+
</div>
|
1706
|
+
</div>
|
1707
|
+
<div class="tags">
|
1708
|
+
<p class="tag_title">Parameters:</p>
|
1709
|
+
<ul class="param">
|
1710
|
+
|
1711
|
+
<li>
|
1712
|
+
|
1713
|
+
<span class='name'>size</span>
|
1714
|
+
|
1715
|
+
|
1716
|
+
<span class='type'>(<tt>Integer</tt>)</span>
|
1717
|
+
|
1718
|
+
|
1719
|
+
|
1720
|
+
—
|
1721
|
+
<div class='inline'>
|
1722
|
+
<p>New Cache size.</p>
|
1723
|
+
</div>
|
1724
|
+
|
1725
|
+
</li>
|
1726
|
+
|
1727
|
+
</ul>
|
1728
|
+
|
1729
|
+
<p class="tag_title">Raises:</p>
|
1730
|
+
<ul class="raise">
|
1731
|
+
|
1732
|
+
<li>
|
1733
|
+
|
1734
|
+
|
1735
|
+
<span class='type'>(<tt><span class='object_link'><a href="UniCache/SizeError.html" title="UniCache::SizeError (class)">SizeError</a></span></tt>)</span>
|
1736
|
+
|
1737
|
+
|
1738
|
+
|
1739
|
+
</li>
|
1740
|
+
|
1741
|
+
</ul>
|
1742
|
+
|
1743
|
+
</div><table class="source_code">
|
1744
|
+
<tr>
|
1745
|
+
<td>
|
1746
|
+
<pre class="lines">
|
1747
|
+
|
1748
|
+
|
1749
|
+
204
|
1750
|
+
205
|
1751
|
+
206
|
1752
|
+
207
|
1753
|
+
208
|
1754
|
+
209
|
1755
|
+
210
|
1756
|
+
211
|
1757
|
+
212
|
1758
|
+
213
|
1759
|
+
214
|
1760
|
+
215
|
1761
|
+
216
|
1762
|
+
217
|
1763
|
+
218
|
1764
|
+
219
|
1765
|
+
220
|
1766
|
+
221
|
1767
|
+
222</pre>
|
1768
|
+
</td>
|
1769
|
+
<td>
|
1770
|
+
<pre class="code"><span class="info file"># File 'lib/unicache.rb', line 204</span>
|
1771
|
+
|
1772
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_resize'>resize</span><span class='lparen'>(</span> <span class='id identifier rubyid_size'>size</span> <span class='rparen'>)</span>
|
1773
|
+
|
1774
|
+
<span class='id identifier rubyid_raise'>raise</span> <span class='const'>SizeError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>UniCache: Size must be bigger than 0</span><span class='tstring_end'>"</span></span> <span class='kw'>unless</span> <span class='id identifier rubyid_size'>size</span> <span class='op'>></span> <span class='int'>0</span>
|
1775
|
+
|
1776
|
+
<span class='ivar'>@lock</span><span class='period'>.</span><span class='id identifier rubyid_lock'>lock</span>
|
1777
|
+
|
1778
|
+
<span class='comment'># Remove entries that does not fit anymore.
|
1779
|
+
</span> <span class='kw'>if</span> <span class='ivar'>@size</span> <span class='op'>&&</span> <span class='id identifier rubyid_size'>size</span> <span class='op'><</span> <span class='ivar'>@size</span>
|
1780
|
+
<span class='lparen'>(</span> <span class='ivar'>@size</span> <span class='op'>-</span> <span class='id identifier rubyid_size'>size</span> <span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_times'>times</span> <span class='kw'>do</span>
|
1781
|
+
<span class='id identifier rubyid__remove'>_remove</span>
|
1782
|
+
<span class='kw'>end</span>
|
1783
|
+
<span class='kw'>end</span>
|
1784
|
+
|
1785
|
+
<span class='id identifier rubyid_ret'>ret</span> <span class='op'>=</span> <span class='ivar'>@size</span> <span class='op'>=</span> <span class='id identifier rubyid_size'>size</span>
|
1786
|
+
|
1787
|
+
<span class='ivar'>@lock</span><span class='period'>.</span><span class='id identifier rubyid_unlock'>unlock</span>
|
1788
|
+
|
1789
|
+
<span class='id identifier rubyid_ret'>ret</span>
|
1790
|
+
<span class='kw'>end</span></pre>
|
1791
|
+
</td>
|
1792
|
+
</tr>
|
1793
|
+
</table>
|
1794
|
+
</div>
|
1795
|
+
|
1796
|
+
<div class="method_details ">
|
1797
|
+
<h3 class="signature " id="setEviction-instance_method">
|
1798
|
+
|
1799
|
+
- (<tt>Object</tt>) <strong>setEviction</strong>(evict)
|
1800
|
+
|
1801
|
+
|
1802
|
+
|
1803
|
+
|
1804
|
+
|
1805
|
+
</h3><div class="docstring">
|
1806
|
+
<div class="discussion">
|
1807
|
+
|
1808
|
+
<p>Set the eviction policy.</p>
|
1809
|
+
|
1810
|
+
|
1811
|
+
</div>
|
1812
|
+
</div>
|
1813
|
+
<div class="tags">
|
1814
|
+
<p class="tag_title">Parameters:</p>
|
1815
|
+
<ul class="param">
|
1816
|
+
|
1817
|
+
<li>
|
1818
|
+
|
1819
|
+
<span class='name'>evict</span>
|
1820
|
+
|
1821
|
+
|
1822
|
+
<span class='type'>(<tt>Object</tt>)</span>
|
1823
|
+
|
1824
|
+
|
1825
|
+
|
1826
|
+
—
|
1827
|
+
<div class='inline'>
|
1828
|
+
<p>Cache eviction policy.</p>
|
1829
|
+
</div>
|
1830
|
+
|
1831
|
+
</li>
|
1832
|
+
|
1833
|
+
</ul>
|
1834
|
+
|
1835
|
+
|
1836
|
+
</div><table class="source_code">
|
1837
|
+
<tr>
|
1838
|
+
<td>
|
1839
|
+
<pre class="lines">
|
1840
|
+
|
1841
|
+
|
1842
|
+
95
|
1843
|
+
96
|
1844
|
+
97</pre>
|
1845
|
+
</td>
|
1846
|
+
<td>
|
1847
|
+
<pre class="code"><span class="info file"># File 'lib/unicache.rb', line 95</span>
|
1848
|
+
|
1849
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_setEviction'>setEviction</span><span class='lparen'>(</span> <span class='id identifier rubyid_evict'>evict</span> <span class='rparen'>)</span>
|
1850
|
+
<span class='ivar'>@evict</span> <span class='op'>=</span> <span class='id identifier rubyid_evict'>evict</span>
|
1851
|
+
<span class='kw'>end</span></pre>
|
1852
|
+
</td>
|
1853
|
+
</tr>
|
1854
|
+
</table>
|
1855
|
+
</div>
|
1856
|
+
|
1857
|
+
<div class="method_details ">
|
1858
|
+
<h3 class="signature " id="store-instance_method">
|
1859
|
+
|
1860
|
+
- (<tt>Object</tt>) <strong>store</strong>
|
1861
|
+
|
1862
|
+
|
1863
|
+
|
1864
|
+
|
1865
|
+
|
1866
|
+
</h3><div class="docstring">
|
1867
|
+
<div class="discussion">
|
1868
|
+
|
1869
|
+
<p>Dummy definition for "store" just for removal.</p>
|
1870
|
+
|
1871
|
+
|
1872
|
+
</div>
|
1873
|
+
</div>
|
1874
|
+
<div class="tags">
|
1875
|
+
|
1876
|
+
|
1877
|
+
</div><table class="source_code">
|
1878
|
+
<tr>
|
1879
|
+
<td>
|
1880
|
+
<pre class="lines">
|
1881
|
+
|
1882
|
+
|
1883
|
+
117</pre>
|
1884
|
+
</td>
|
1885
|
+
<td>
|
1886
|
+
<pre class="code"><span class="info file"># File 'lib/unicache.rb', line 117</span>
|
1887
|
+
|
1888
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_store'>store</span><span class='lparen'>(</span><span class='rparen'>)</span><span class='semicolon'>;</span> <span class='kw'>end</span></pre>
|
1889
|
+
</td>
|
1890
|
+
</tr>
|
1891
|
+
</table>
|
1892
|
+
</div>
|
1893
|
+
|
1894
|
+
</div>
|
1895
|
+
|
1896
|
+
</div>
|
1897
|
+
|
1898
|
+
<div id="footer">
|
1899
|
+
Generated on Tue Dec 31 14:00:42 2013 by
|
1900
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
1901
|
+
0.8.6.1 (ruby-1.9.3).
|
1902
|
+
</div>
|
1903
|
+
|
1904
|
+
</body>
|
1905
|
+
</html>
|