elephas 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/.gitignore +5 -0
  2. data/.travis.yml +8 -0
  3. data/.yardopts +1 -0
  4. data/Gemfile +9 -0
  5. data/README.md +28 -0
  6. data/Rakefile +18 -0
  7. data/doc/Elephas/Cache.html +815 -0
  8. data/doc/Elephas/Entry.html +1085 -0
  9. data/doc/Elephas/Exceptions.html +115 -0
  10. data/doc/Elephas/Providers/Base.html +701 -0
  11. data/doc/Elephas/Providers/Hash.html +775 -0
  12. data/doc/Elephas/Providers/RubyOnRails.html +609 -0
  13. data/doc/Elephas/Providers.html +129 -0
  14. data/doc/Elephas/Version.html +189 -0
  15. data/doc/Elephas.html +130 -0
  16. data/doc/_index.html +207 -0
  17. data/doc/class_list.html +53 -0
  18. data/doc/css/common.css +1 -0
  19. data/doc/css/full_list.css +57 -0
  20. data/doc/css/style.css +328 -0
  21. data/doc/file.README.html +103 -0
  22. data/doc/file_list.html +55 -0
  23. data/doc/frames.html +28 -0
  24. data/doc/index.html +103 -0
  25. data/doc/js/app.js +214 -0
  26. data/doc/js/full_list.js +173 -0
  27. data/doc/js/jquery.js +4 -0
  28. data/doc/method_list.html +300 -0
  29. data/doc/top-level-namespace.html +112 -0
  30. data/elephas.gemspec +34 -0
  31. data/lib/elephas/cache.rb +89 -0
  32. data/lib/elephas/entry.rb +86 -0
  33. data/lib/elephas/provider.rb +57 -0
  34. data/lib/elephas/providers/hash.rb +65 -0
  35. data/lib/elephas/providers/ruby_on_rails.rb +57 -0
  36. data/lib/elephas/version.rb +25 -0
  37. data/lib/elephas.rb +20 -0
  38. data/spec/coverage_helper.rb +19 -0
  39. data/spec/elephas/cache_spec.rb +41 -0
  40. data/spec/elephas/entry_spec.rb +11 -0
  41. data/spec/elephas/provider_spec.rb +46 -0
  42. data/spec/elephas/providers/hash_spec.rb +80 -0
  43. data/spec/elephas/providers/ruby_on_rails_spec.rb +86 -0
  44. data/spec/spec_helper.rb +16 -0
  45. metadata +231 -0
@@ -0,0 +1,815 @@
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: Elephas::Cache
8
+
9
+ &mdash; Documentation by YARD 0.8.2.1
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="../css/style.css" type="text/css" media="screen" charset="utf-8" />
14
+
15
+ <link rel="stylesheet" href="../css/common.css" type="text/css" media="screen" 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 (C)</a> &raquo;
35
+ <span class='title'><span class='object_link'><a href="../Elephas.html" title="Elephas (module)">Elephas</a></span></span>
36
+ &raquo;
37
+ <span class="title">Cache</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: Elephas::Cache
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">Object</span>
77
+
78
+ <ul class="fullTree">
79
+ <li>Object</li>
80
+
81
+ <li class="next">Elephas::Cache</li>
82
+
83
+ </ul>
84
+ <a href="#" class="inheritanceTree">show all</a>
85
+
86
+ </dd>
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+ <dt class="r2 last">Defined in:</dt>
97
+ <dd class="r2 last">lib/elephas/cache.rb</dd>
98
+
99
+ </dl>
100
+ <div class="clear"></div>
101
+
102
+ <h2>Overview</h2><div class="docstring">
103
+ <div class="discussion">
104
+ <p>This is the main class of the framework. Use only this class to access the cache.</p>
105
+
106
+
107
+ </div>
108
+ </div>
109
+ <div class="tags">
110
+
111
+
112
+ </div>
113
+
114
+
115
+
116
+ <h2>Class Attribute Summary <small>(<a href="#" class="summary_toggle">collapse</a>)</small></h2>
117
+ <ul class="summary">
118
+
119
+ <li class="public ">
120
+ <span class="summary_signature">
121
+
122
+ <a href="#provider-class_method" title="provider (class method)">+ (Object) <strong>provider</strong> </a>
123
+
124
+
125
+
126
+ </span>
127
+
128
+
129
+
130
+
131
+
132
+
133
+
134
+
135
+
136
+
137
+
138
+
139
+ <span class="summary_desc"><div class='inline'><p>The provider used for the caching.</p>
140
+ </div></span>
141
+
142
+ </li>
143
+
144
+
145
+ </ul>
146
+
147
+
148
+
149
+
150
+
151
+ <h2>
152
+ Class Method Summary
153
+ <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
154
+ </h2>
155
+
156
+ <ul class="summary">
157
+
158
+ <li class="public ">
159
+ <span class="summary_signature">
160
+
161
+ <a href="#delete-class_method" title="delete (class method)">+ (TrueClass|FalseClass) <strong>delete</strong>(key) </a>
162
+
163
+
164
+
165
+ </span>
166
+
167
+
168
+
169
+
170
+
171
+
172
+
173
+
174
+
175
+ <span class="summary_desc"><div class='inline'><p>Deletes a value from the cache.</p>
176
+ </div></span>
177
+
178
+ </li>
179
+
180
+
181
+ <li class="public ">
182
+ <span class="summary_signature">
183
+
184
+ <a href="#exists%3F-class_method" title="exists? (class method)">+ (TrueClass|FalseClass) <strong>exists?</strong>(key) </a>
185
+
186
+
187
+
188
+ </span>
189
+
190
+
191
+
192
+
193
+
194
+
195
+
196
+
197
+
198
+ <span class="summary_desc"><div class='inline'><p>Checks if a key exists in the cache.</p>
199
+ </div></span>
200
+
201
+ </li>
202
+
203
+
204
+ <li class="public ">
205
+ <span class="summary_signature">
206
+
207
+ <a href="#read-class_method" title="read (class method)">+ (Object|NilClass) <strong>read</strong>(key) </a>
208
+
209
+
210
+
211
+ </span>
212
+
213
+
214
+
215
+
216
+
217
+
218
+
219
+
220
+
221
+ <span class="summary_desc"><div class='inline'><p>Reads a value from the cache.</p>
222
+ </div></span>
223
+
224
+ </li>
225
+
226
+
227
+ <li class="public ">
228
+ <span class="summary_signature">
229
+
230
+ <a href="#use-class_method" title="use (class method)">+ (Object|Entry) <strong>use</strong>(key, options = {}) </a>
231
+
232
+
233
+
234
+ </span>
235
+
236
+
237
+
238
+
239
+
240
+
241
+
242
+
243
+
244
+ <span class="summary_desc"><div class='inline'><p>This is the main method of the framework.</p>
245
+ </div></span>
246
+
247
+ </li>
248
+
249
+
250
+ <li class="public ">
251
+ <span class="summary_signature">
252
+
253
+ <a href="#write-class_method" title="write (class method)">+ (Object) <strong>write</strong>(key, value, options = {}) </a>
254
+
255
+
256
+
257
+ </span>
258
+
259
+
260
+
261
+
262
+
263
+
264
+
265
+
266
+
267
+ <span class="summary_desc"><div class='inline'><p>Writes a value to the cache.</p>
268
+ </div></span>
269
+
270
+ </li>
271
+
272
+
273
+ </ul>
274
+
275
+
276
+
277
+ <div id="class_attr_details" class="attr_details">
278
+ <h2>Class Attribute Details</h2>
279
+
280
+
281
+ <span id="provider=-class_method"></span>
282
+ <div class="method_details first">
283
+ <h3 class="signature first" id="provider-class_method">
284
+
285
+ + (<tt>Object</tt>) <strong>provider</strong>
286
+
287
+
288
+
289
+
290
+
291
+ </h3><div class="docstring">
292
+ <div class="discussion">
293
+ <p>The provider used for the caching.</p>
294
+
295
+
296
+ </div>
297
+ </div>
298
+ <div class="tags">
299
+
300
+
301
+ </div><table class="source_code">
302
+ <tr>
303
+ <td>
304
+ <pre class="lines">
305
+
306
+
307
+ 12
308
+ 13
309
+ 14</pre>
310
+ </td>
311
+ <td>
312
+ <pre class="code"><span class="info file"># File 'lib/elephas/cache.rb', line 12</span>
313
+
314
+ <span class='kw'>def</span> <span class='id identifier rubyid_provider'>provider</span>
315
+ <span class='ivar'>@provider</span>
316
+ <span class='kw'>end</span></pre>
317
+ </td>
318
+ </tr>
319
+ </table>
320
+ </div>
321
+
322
+ </div>
323
+
324
+
325
+ <div id="class_method_details" class="method_details_list">
326
+ <h2>Class Method Details</h2>
327
+
328
+
329
+ <div class="method_details first">
330
+ <h3 class="signature first" id="delete-class_method">
331
+
332
+ + (<tt>TrueClass|FalseClass</tt>) <strong>delete</strong>(key)
333
+
334
+
335
+
336
+
337
+
338
+ </h3><div class="docstring">
339
+ <div class="discussion">
340
+ <p>Deletes a value from the cache.</p>
341
+
342
+
343
+ </div>
344
+ </div>
345
+ <div class="tags">
346
+ <p class="tag_title">Parameters:</p>
347
+ <ul class="param">
348
+
349
+ <li>
350
+
351
+ <span class='name'>key</span>
352
+
353
+
354
+ <span class='type'>(<tt>String</tt>)</span>
355
+
356
+
357
+
358
+ &mdash;
359
+ <div class='inline'><p>The key to delete.</p>
360
+ </div>
361
+
362
+ </li>
363
+
364
+ </ul>
365
+
366
+ <p class="tag_title">Returns:</p>
367
+ <ul class="return">
368
+
369
+ <li>
370
+
371
+
372
+ <span class='type'>(<tt>TrueClass|FalseClass</tt>)</span>
373
+
374
+
375
+
376
+ &mdash;
377
+ <div class='inline'><p><code>true</code> if the key was in the cache, <code>false</code> otherwise.</p>
378
+ </div>
379
+
380
+ </li>
381
+
382
+ </ul>
383
+
384
+ </div><table class="source_code">
385
+ <tr>
386
+ <td>
387
+ <pre class="lines">
388
+
389
+
390
+ 76
391
+ 77
392
+ 78</pre>
393
+ </td>
394
+ <td>
395
+ <pre class="code"><span class="info file"># File 'lib/elephas/cache.rb', line 76</span>
396
+
397
+ <span class='kw'>def</span> <span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span>
398
+ <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_provider'>provider</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span>
399
+ <span class='kw'>end</span></pre>
400
+ </td>
401
+ </tr>
402
+ </table>
403
+ </div>
404
+
405
+ <div class="method_details ">
406
+ <h3 class="signature " id="exists?-class_method">
407
+
408
+ + (<tt>TrueClass|FalseClass</tt>) <strong>exists?</strong>(key)
409
+
410
+
411
+
412
+
413
+
414
+ </h3><div class="docstring">
415
+ <div class="discussion">
416
+ <p>Checks if a key exists in the cache.</p>
417
+
418
+
419
+ </div>
420
+ </div>
421
+ <div class="tags">
422
+ <p class="tag_title">Parameters:</p>
423
+ <ul class="param">
424
+
425
+ <li>
426
+
427
+ <span class='name'>key</span>
428
+
429
+
430
+ <span class='type'>(<tt>String</tt>)</span>
431
+
432
+
433
+
434
+ &mdash;
435
+ <div class='inline'><p>The key to lookup.</p>
436
+ </div>
437
+
438
+ </li>
439
+
440
+ </ul>
441
+
442
+ <p class="tag_title">Returns:</p>
443
+ <ul class="return">
444
+
445
+ <li>
446
+
447
+
448
+ <span class='type'>(<tt>TrueClass|FalseClass</tt>)</span>
449
+
450
+
451
+
452
+ &mdash;
453
+ <div class='inline'><p><code>true</code> if the key is in the cache, <code>false</code> otherwise.</p>
454
+ </div>
455
+
456
+ </li>
457
+
458
+ </ul>
459
+
460
+ </div><table class="source_code">
461
+ <tr>
462
+ <td>
463
+ <pre class="lines">
464
+
465
+
466
+ 84
467
+ 85
468
+ 86</pre>
469
+ </td>
470
+ <td>
471
+ <pre class="code"><span class="info file"># File 'lib/elephas/cache.rb', line 84</span>
472
+
473
+ <span class='kw'>def</span> <span class='id identifier rubyid_exists?'>exists?</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span>
474
+ <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_provider'>provider</span><span class='period'>.</span><span class='id identifier rubyid_exists?'>exists?</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span>
475
+ <span class='kw'>end</span></pre>
476
+ </td>
477
+ </tr>
478
+ </table>
479
+ </div>
480
+
481
+ <div class="method_details ">
482
+ <h3 class="signature " id="read-class_method">
483
+
484
+ + (<tt>Object|NilClass</tt>) <strong>read</strong>(key)
485
+
486
+
487
+
488
+
489
+
490
+ </h3><div class="docstring">
491
+ <div class="discussion">
492
+ <p>Reads a value from the cache.</p>
493
+
494
+
495
+ </div>
496
+ </div>
497
+ <div class="tags">
498
+ <p class="tag_title">Parameters:</p>
499
+ <ul class="param">
500
+
501
+ <li>
502
+
503
+ <span class='name'>key</span>
504
+
505
+
506
+ <span class='type'>(<tt>String</tt>)</span>
507
+
508
+
509
+
510
+ &mdash;
511
+ <div class='inline'><p>The key to lookup.</p>
512
+ </div>
513
+
514
+ </li>
515
+
516
+ </ul>
517
+
518
+ <p class="tag_title">Returns:</p>
519
+ <ul class="return">
520
+
521
+ <li>
522
+
523
+
524
+ <span class='type'>(<tt>Object|NilClass</tt>)</span>
525
+
526
+
527
+
528
+ &mdash;
529
+ <div class='inline'><p>The read value or <code>nil</code>.</p>
530
+ </div>
531
+
532
+ </li>
533
+
534
+ </ul>
535
+
536
+ </div><table class="source_code">
537
+ <tr>
538
+ <td>
539
+ <pre class="lines">
540
+
541
+
542
+ 55
543
+ 56
544
+ 57</pre>
545
+ </td>
546
+ <td>
547
+ <pre class="code"><span class="info file"># File 'lib/elephas/cache.rb', line 55</span>
548
+
549
+ <span class='kw'>def</span> <span class='id identifier rubyid_read'>read</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span>
550
+ <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_provider'>provider</span><span class='period'>.</span><span class='id identifier rubyid_read'>read</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span>
551
+ <span class='kw'>end</span></pre>
552
+ </td>
553
+ </tr>
554
+ </table>
555
+ </div>
556
+
557
+ <div class="method_details ">
558
+ <h3 class="signature " id="use-class_method">
559
+
560
+ + (<tt>Object|<span class='object_link'><a href="Entry.html" title="Elephas::Entry (class)">Entry</a></span></tt>) <strong>use</strong>(key, options = {})
561
+
562
+
563
+
564
+
565
+
566
+ </h3><div class="docstring">
567
+ <div class="discussion">
568
+ <p>This is the main method of the framework.
569
+ It tries reading a key from the cache. If it doesn&#39;t find it, it uses the provided block to compute its value and then store it into the cache for later usages.</p>
570
+
571
+
572
+ </div>
573
+ </div>
574
+ <div class="tags">
575
+ <p class="tag_title">Parameters:</p>
576
+ <ul class="param">
577
+
578
+ <li>
579
+
580
+ <span class='name'>key</span>
581
+
582
+
583
+ <span class='type'>(<tt>String</tt>)</span>
584
+
585
+
586
+
587
+ &mdash;
588
+ <div class='inline'><p>The key to lookup.</p>
589
+ </div>
590
+
591
+ </li>
592
+
593
+ </ul>
594
+
595
+ <p class="tag_title">Returns:</p>
596
+ <ul class="return">
597
+
598
+ <li>
599
+
600
+
601
+ <span class='type'>(<tt>Object|<span class='object_link'><a href="Entry.html" title="Elephas::Entry (class)">Entry</a></span></tt>)</span>
602
+
603
+
604
+
605
+ &mdash;
606
+ <div class='inline'><p>The found or newly-set value associated to the key.</p>
607
+ </div>
608
+
609
+ </li>
610
+
611
+ </ul>
612
+
613
+ </div><table class="source_code">
614
+ <tr>
615
+ <td>
616
+ <pre class="lines">
617
+
618
+
619
+ 19
620
+ 20
621
+ 21
622
+ 22
623
+ 23
624
+ 24
625
+ 25
626
+ 26
627
+ 27
628
+ 28
629
+ 29
630
+ 30
631
+ 31
632
+ 32
633
+ 33
634
+ 34
635
+ 35
636
+ 36
637
+ 37
638
+ 38
639
+ 39
640
+ 40
641
+ 41
642
+ 42
643
+ 43
644
+ 44
645
+ 45
646
+ 46
647
+ 47
648
+ 48
649
+ 49</pre>
650
+ </td>
651
+ <td>
652
+ <pre class="code"><span class="info file"># File 'lib/elephas/cache.rb', line 19</span>
653
+
654
+ <span class='kw'>def</span> <span class='id identifier rubyid_use'>use</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
655
+ <span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='kw'>nil</span>
656
+
657
+ <span class='comment'># Get options
658
+ </span> <span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span> <span class='kw'>if</span> <span class='op'>!</span><span class='id identifier rubyid_options'>options</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='op'>::</span><span class='const'>Hash</span><span class='rparen'>)</span>
659
+ <span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='symbol'>:ttl</span> <span class='op'>=&gt;</span> <span class='int'>1</span><span class='period'>.</span><span class='id identifier rubyid_hour'>hour</span><span class='comma'>,</span> <span class='symbol'>:force</span> <span class='op'>=&gt;</span> <span class='kw'>false</span><span class='comma'>,</span> <span class='symbol'>:as_entry</span> <span class='op'>=&gt;</span> <span class='kw'>false</span><span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_merge'>merge</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span>
660
+ <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:ttl</span><span class='rbracket'>]</span> <span class='op'>==</span> <span class='lbracket'>[</span><span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:ttl</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_to_integer'>to_integer</span><span class='comma'>,</span> <span class='int'>0</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_max'>max</span>
661
+ <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:force</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:force</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_to_boolean'>to_boolean</span>
662
+ <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:prefix</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:prefix</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span> <span class='op'>?</span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:prefix</span><span class='rbracket'>]</span> <span class='op'>:</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>elephas-</span><span class='embexpr_beg'>#{</span><span class='op'>::</span><span class='const'>Elephas</span><span class='op'>::</span><span class='const'>Version</span><span class='op'>::</span><span class='const'>STRING</span><span class='rbrace'>}</span><span class='tstring_content'>-cache</span><span class='tstring_end'>&quot;</span></span>
663
+
664
+ <span class='comment'># Wrap the final key to ensure we don't have colliding namespaces.
665
+ </span> <span class='id identifier rubyid_fkey'>fkey</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:prefix</span><span class='rbracket'>]</span><span class='rbrace'>}</span><span class='tstring_content'>[</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_key'>key</span><span class='rbrace'>}</span><span class='tstring_content'>]</span><span class='tstring_end'>&quot;</span></span>
666
+
667
+ <span class='comment'># Compute the hash key used for referencing this value
668
+ </span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:hash</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:hash</span><span class='rbracket'>]</span> <span class='op'>||</span> <span class='op'>::</span><span class='const'>Elephas</span><span class='op'>::</span><span class='const'>Entry</span><span class='period'>.</span><span class='id identifier rubyid_hashify_key'>hashify_key</span><span class='lparen'>(</span><span class='id identifier rubyid_fkey'>fkey</span><span class='period'>.</span><span class='id identifier rubyid_ensure_string'>ensure_string</span><span class='rparen'>)</span>
669
+
670
+ <span class='comment'># Check if the storage has the value (if we don't have to skip the cache)
671
+ </span> <span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_provider'>provider</span><span class='period'>.</span><span class='id identifier rubyid_read'>read</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:hash</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:force</span><span class='rbracket'>]</span> <span class='op'>==</span> <span class='kw'>false</span> <span class='op'>&amp;&amp;</span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:ttl</span><span class='rbracket'>]</span> <span class='op'>&gt;</span> <span class='int'>0</span>
672
+
673
+ <span class='kw'>if</span> <span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span> <span class='op'>&amp;&amp;</span> <span class='id identifier rubyid_block_given?'>block_given?</span> <span class='kw'>then</span> <span class='comment'># Try to compute the value from the block
674
+ </span> <span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='kw'>yield</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span>
675
+
676
+ <span class='kw'>if</span> <span class='id identifier rubyid_rv'>rv</span> <span class='op'>&amp;&amp;</span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:ttl</span><span class='rbracket'>]</span> <span class='op'>&gt;</span> <span class='int'>0</span> <span class='kw'>then</span> <span class='comment'># We have a value and we have to store it
677
+ </span> <span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='op'>::</span><span class='const'>Elephas</span><span class='op'>::</span><span class='const'>Entry</span><span class='period'>.</span><span class='id identifier rubyid_ensure'>ensure</span><span class='lparen'>(</span><span class='id identifier rubyid_rv'>rv</span><span class='comma'>,</span> <span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span> <span class='comment'># Make sure is an entry
678
+ </span> <span class='const'>Elephas</span><span class='op'>::</span><span class='const'>Cache</span><span class='period'>.</span><span class='id identifier rubyid_write'>write</span><span class='lparen'>(</span><span class='id identifier rubyid_fkey'>fkey</span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span>
679
+ <span class='kw'>end</span>
680
+ <span class='kw'>end</span>
681
+
682
+ <span class='comment'># Return value
683
+ </span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:as_entry</span><span class='rbracket'>]</span> <span class='op'>?</span> <span class='id identifier rubyid_rv'>rv</span> <span class='op'>:</span> <span class='id identifier rubyid_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_dup'>dup</span>
684
+ <span class='kw'>end</span></pre>
685
+ </td>
686
+ </tr>
687
+ </table>
688
+ </div>
689
+
690
+ <div class="method_details ">
691
+ <h3 class="signature " id="write-class_method">
692
+
693
+ + (<tt>Object</tt>) <strong>write</strong>(key, value, options = {})
694
+
695
+
696
+
697
+
698
+
699
+ </h3><div class="docstring">
700
+ <div class="discussion">
701
+ <p>Writes a value to the cache.</p>
702
+
703
+ <p>TODO: Insert options documentation.</p>
704
+
705
+
706
+ </div>
707
+ </div>
708
+ <div class="tags">
709
+ <p class="tag_title">Parameters:</p>
710
+ <ul class="param">
711
+
712
+ <li>
713
+
714
+ <span class='name'>key</span>
715
+
716
+
717
+ <span class='type'>(<tt>String</tt>)</span>
718
+
719
+
720
+
721
+ &mdash;
722
+ <div class='inline'><p>The key to associate the value with.</p>
723
+ </div>
724
+
725
+ </li>
726
+
727
+ <li>
728
+
729
+ <span class='name'>value</span>
730
+
731
+
732
+ <span class='type'>(<tt>Object</tt>)</span>
733
+
734
+
735
+
736
+ &mdash;
737
+ <div class='inline'><p>The value to write. Setting a value to <code>nil</code> <strong>doesn&#39;t</strong> mean <em>deleting</em> the value.</p>
738
+ </div>
739
+
740
+ </li>
741
+
742
+ <li>
743
+
744
+ <span class='name'>options</span>
745
+
746
+
747
+ <span class='type'>(<tt>Hash</tt>)</span>
748
+
749
+
750
+ <em class="default">(defaults to: <tt>{}</tt>)</em>
751
+
752
+
753
+ &mdash;
754
+ <div class='inline'><p>A list of options for writing.</p>
755
+ </div>
756
+
757
+ </li>
758
+
759
+ </ul>
760
+
761
+ <p class="tag_title">Returns:</p>
762
+ <ul class="return">
763
+
764
+ <li>
765
+
766
+
767
+ <span class='type'>(<tt>Object</tt>)</span>
768
+
769
+
770
+
771
+ &mdash;
772
+ <div class='inline'><p>The value itself.</p>
773
+ </div>
774
+
775
+ </li>
776
+
777
+ </ul>
778
+
779
+ </div><table class="source_code">
780
+ <tr>
781
+ <td>
782
+ <pre class="lines">
783
+
784
+
785
+ 66
786
+ 67
787
+ 68
788
+ 69
789
+ 70</pre>
790
+ </td>
791
+ <td>
792
+ <pre class="code"><span class="info file"># File 'lib/elephas/cache.rb', line 66</span>
793
+
794
+ <span class='kw'>def</span> <span class='id identifier rubyid_write'>write</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='comma'>,</span> <span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
795
+ <span class='comment'># TODO: Handle options
796
+ </span>
797
+ <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_provider'>provider</span><span class='period'>.</span><span class='id identifier rubyid_write'>write</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='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span>
798
+ <span class='kw'>end</span></pre>
799
+ </td>
800
+ </tr>
801
+ </table>
802
+ </div>
803
+
804
+ </div>
805
+
806
+ </div>
807
+
808
+ <div id="footer">
809
+ Generated on Sat Jul 28 14:29:52 2012 by
810
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
811
+ 0.8.2.1 (ruby-1.9.2).
812
+ </div>
813
+
814
+ </body>
815
+ </html>