elephas 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -4,21 +4,49 @@
4
4
  [![Dependency Status](https://gemnasium.com/ShogunPanda/elephas.png?travis)](https://gemnasium.com/ShogunPanda/elephas)
5
5
 
6
6
  A storage agnostic caching framework.
7
+
7
8
  http://github.com/ShogunPanda/elephas
8
9
 
9
10
  ## Usage
10
11
 
11
- *TODO*
12
+ The usage of the framework is really simple.
13
+
14
+ At first you have to setup a provider (that is, a storage) for the Elephas. By default it uses an internal hash, and also Rails is supported.
15
+
16
+ ```ruby
17
+ Elephas::Cache.provider = Elephas::Providers::RubyOnRails.new
18
+ ```
19
+
20
+ After that, you can query the framework for a value use the `use` method.
21
+
22
+ You should also pass a block to the method, so that the framework use that for computing the value of the cache entry.
23
+
24
+ ```ruby
25
+ value = Elephas::Cache.use("KEY") do |options|
26
+ "VALUE"
27
+ end
28
+ # => "VALUE"
29
+ ```
30
+
31
+ The next time you issue this call, the block won't be called.
32
+
33
+ The block takes an argument, which contains all the options for the entry.
34
+
35
+ You can see ``Elephas::Cache.setup_options`` documentation to see what options are supported.
36
+
37
+ For now, you just have to know that you can set the ```:ttl``` option to specify how long the value will stay in the cache (in milliseconds). Setting it to a non-positive value means to never cache the value.
12
38
 
13
39
  See documentation for more informations.
14
40
 
41
+ **You're done!**
42
+
15
43
  ## Contributing to elephas
16
44
 
17
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
18
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
19
- * Fork the project
20
- * Start a feature/bugfix branch
21
- * Commit and push until you are happy with your contribution
45
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
46
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
47
+ * Fork the project.
48
+ * Start a feature/bugfix branch.
49
+ * Commit and push until you are happy with your contribution.
22
50
  * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
23
51
  * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
24
52
 
@@ -158,7 +158,30 @@
158
158
  <li class="public ">
159
159
  <span class="summary_signature">
160
160
 
161
- <a href="#delete-class_method" title="delete (class method)">+ (TrueClass|FalseClass) <strong>delete</strong>(key) </a>
161
+ <a href="#default_prefix-class_method" title="default_prefix (class method)">+ (String) <strong>default_prefix</strong> </a>
162
+
163
+
164
+
165
+ </span>
166
+
167
+
168
+
169
+
170
+
171
+
172
+
173
+
174
+
175
+ <span class="summary_desc"><div class='inline'><p>Returns the default prefix for cache entries.</p>
176
+ </div></span>
177
+
178
+ </li>
179
+
180
+
181
+ <li class="public ">
182
+ <span class="summary_signature">
183
+
184
+ <a href="#delete-class_method" title="delete (class method)">+ (Boolean) <strong>delete</strong>(key) </a>
162
185
 
163
186
 
164
187
 
@@ -181,7 +204,7 @@
181
204
  <li class="public ">
182
205
  <span class="summary_signature">
183
206
 
184
- <a href="#exists%3F-class_method" title="exists? (class method)">+ (TrueClass|FalseClass) <strong>exists?</strong>(key) </a>
207
+ <a href="#exists%3F-class_method" title="exists? (class method)">+ (Boolean) <strong>exists?</strong>(key) </a>
185
208
 
186
209
 
187
210
 
@@ -221,6 +244,29 @@
221
244
  <span class="summary_desc"><div class='inline'><p>Reads a value from the cache.</p>
222
245
  </div></span>
223
246
 
247
+ </li>
248
+
249
+
250
+ <li class="public ">
251
+ <span class="summary_signature">
252
+
253
+ <a href="#setup_options-class_method" title="setup_options (class method)">+ (Hash) <strong>setup_options</strong>(options, key) </a>
254
+
255
+
256
+
257
+ </span>
258
+
259
+
260
+
261
+
262
+
263
+
264
+
265
+
266
+
267
+ <span class="summary_desc"><div class='inline'><p>Setups options for use into the framework.</p>
268
+ </div></span>
269
+
224
270
  </li>
225
271
 
226
272
 
@@ -327,9 +373,66 @@
327
373
 
328
374
 
329
375
  <div class="method_details first">
330
- <h3 class="signature first" id="delete-class_method">
376
+ <h3 class="signature first" id="default_prefix-class_method">
331
377
 
332
- + (<tt>TrueClass|FalseClass</tt>) <strong>delete</strong>(key)
378
+ + (<tt>String</tt>) <strong>default_prefix</strong>
379
+
380
+
381
+
382
+
383
+
384
+ </h3><div class="docstring">
385
+ <div class="discussion">
386
+ <p>Returns the default prefix for cache entries.</p>
387
+
388
+
389
+ </div>
390
+ </div>
391
+ <div class="tags">
392
+
393
+ <p class="tag_title">Returns:</p>
394
+ <ul class="return">
395
+
396
+ <li>
397
+
398
+
399
+ <span class='type'>(<tt>String</tt>)</span>
400
+
401
+
402
+
403
+ &mdash;
404
+ <div class='inline'><p>The default prefix for cache entries.</p>
405
+ </div>
406
+
407
+ </li>
408
+
409
+ </ul>
410
+
411
+ </div><table class="source_code">
412
+ <tr>
413
+ <td>
414
+ <pre class="lines">
415
+
416
+
417
+ 96
418
+ 97
419
+ 98</pre>
420
+ </td>
421
+ <td>
422
+ <pre class="code"><span class="info file"># File 'lib/elephas/cache.rb', line 96</span>
423
+
424
+ <span class='kw'>def</span> <span class='id identifier rubyid_default_prefix'>default_prefix</span>
425
+ <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>
426
+ <span class='kw'>end</span></pre>
427
+ </td>
428
+ </tr>
429
+ </table>
430
+ </div>
431
+
432
+ <div class="method_details ">
433
+ <h3 class="signature " id="delete-class_method">
434
+
435
+ + (<tt>Boolean</tt>) <strong>delete</strong>(key)
333
436
 
334
437
 
335
438
 
@@ -369,7 +472,7 @@
369
472
  <li>
370
473
 
371
474
 
372
- <span class='type'>(<tt>TrueClass|FalseClass</tt>)</span>
475
+ <span class='type'>(<tt>Boolean</tt>)</span>
373
476
 
374
477
 
375
478
 
@@ -387,12 +490,12 @@
387
490
  <pre class="lines">
388
491
 
389
492
 
390
- 76
391
- 77
392
- 78</pre>
493
+ 81
494
+ 82
495
+ 83</pre>
393
496
  </td>
394
497
  <td>
395
- <pre class="code"><span class="info file"># File 'lib/elephas/cache.rb', line 76</span>
498
+ <pre class="code"><span class="info file"># File 'lib/elephas/cache.rb', line 81</span>
396
499
 
397
500
  <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
501
  <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>
@@ -405,7 +508,7 @@
405
508
  <div class="method_details ">
406
509
  <h3 class="signature " id="exists?-class_method">
407
510
 
408
- + (<tt>TrueClass|FalseClass</tt>) <strong>exists?</strong>(key)
511
+ + (<tt>Boolean</tt>) <strong>exists?</strong>(key)
409
512
 
410
513
 
411
514
 
@@ -445,7 +548,7 @@
445
548
  <li>
446
549
 
447
550
 
448
- <span class='type'>(<tt>TrueClass|FalseClass</tt>)</span>
551
+ <span class='type'>(<tt>Boolean</tt>)</span>
449
552
 
450
553
 
451
554
 
@@ -463,12 +566,12 @@
463
566
  <pre class="lines">
464
567
 
465
568
 
466
- 84
467
- 85
468
- 86</pre>
569
+ 89
570
+ 90
571
+ 91</pre>
469
572
  </td>
470
573
  <td>
471
- <pre class="code"><span class="info file"># File 'lib/elephas/cache.rb', line 84</span>
574
+ <pre class="code"><span class="info file"># File 'lib/elephas/cache.rb', line 89</span>
472
575
 
473
576
  <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
577
  <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>
@@ -539,12 +642,12 @@
539
642
  <pre class="lines">
540
643
 
541
644
 
542
- 55
543
- 56
544
- 57</pre>
645
+ 62
646
+ 63
647
+ 64</pre>
545
648
  </td>
546
649
  <td>
547
- <pre class="code"><span class="info file"># File 'lib/elephas/cache.rb', line 55</span>
650
+ <pre class="code"><span class="info file"># File 'lib/elephas/cache.rb', line 62</span>
548
651
 
549
652
  <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
653
  <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>
@@ -552,6 +655,134 @@
552
655
  </td>
553
656
  </tr>
554
657
  </table>
658
+ </div>
659
+
660
+ <div class="method_details ">
661
+ <h3 class="signature " id="setup_options-class_method">
662
+
663
+ + (<tt>Hash</tt>) <strong>setup_options</strong>(options, key)
664
+
665
+
666
+
667
+
668
+
669
+ </h3><div class="docstring">
670
+ <div class="discussion">
671
+ <p>Setups options for use into the framework.
672
+ Valid options are:</p>
673
+
674
+ <ul>
675
+ <li><strong>:ttl</strong>: The TTL (time to live, in milliseconds) of the entry. It means how long will the value stay in cache. Setting it to 0 or less means never cache the entry.</li>
676
+ <li><strong>:force</strong>: Setting it to <code>true</code> will always skip the cache.</li>
677
+ <li><strong>:key</strong>: The key associated to this value. <strong>You should never set this option directly.</strong></li>
678
+ <li><strong>:prefix</strong>: The prefix used in cache. This is used to avoid conflicts with other caching frameworks.</li>
679
+ <li><strong>:complete_key</strong>: The complete key used for computing the hash. By default is concatenation of <code>:key</code> and <code>:prefix</code> options.</li>
680
+ <li><strong>:hash</strong>: The hash used to store the key in the cache. Should be unique</li>
681
+ <li><strong>:as_entry</strong>: In <code>Elephas::Cache.use</code>, setting this to <code>true</code> will return the entire <code>Entry</code> object rather than the value only.</li>
682
+ </ul>
683
+
684
+
685
+ </div>
686
+ </div>
687
+ <div class="tags">
688
+ <p class="tag_title">Parameters:</p>
689
+ <ul class="param">
690
+
691
+ <li>
692
+
693
+ <span class='name'>options</span>
694
+
695
+
696
+ <span class='type'>(<tt>Object</tt>)</span>
697
+
698
+
699
+
700
+ &mdash;
701
+ <div class='inline'><p>An initial setup.</p>
702
+ </div>
703
+
704
+ </li>
705
+
706
+ <li>
707
+
708
+ <span class='name'>key</span>
709
+
710
+
711
+ <span class='type'>(<tt>String</tt>)</span>
712
+
713
+
714
+
715
+ &mdash;
716
+ <div class='inline'><p>The key to associate to this options.</p>
717
+ </div>
718
+
719
+ </li>
720
+
721
+ </ul>
722
+
723
+ <p class="tag_title">Returns:</p>
724
+ <ul class="return">
725
+
726
+ <li>
727
+
728
+
729
+ <span class='type'>(<tt>Hash</tt>)</span>
730
+
731
+
732
+
733
+ &mdash;
734
+ <div class='inline'><p>An options hash.</p>
735
+ </div>
736
+
737
+ </li>
738
+
739
+ </ul>
740
+
741
+ </div><table class="source_code">
742
+ <tr>
743
+ <td>
744
+ <pre class="lines">
745
+
746
+
747
+ 114
748
+ 115
749
+ 116
750
+ 117
751
+ 118
752
+ 119
753
+ 120
754
+ 121
755
+ 122
756
+ 123
757
+ 124
758
+ 125
759
+ 126
760
+ 127
761
+ 128
762
+ 129</pre>
763
+ </td>
764
+ <td>
765
+ <pre class="code"><span class="info file"># File 'lib/elephas/cache.rb', line 114</span>
766
+
767
+ <span class='kw'>def</span> <span class='id identifier rubyid_setup_options'>setup_options</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span>
768
+ <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>
769
+ <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='op'>*</span> <span class='int'>1000</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>
770
+ <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:key</span><span class='rbracket'>]</span> <span class='op'>||=</span> <span class='id identifier rubyid_key'>key</span><span class='period'>.</span><span class='id identifier rubyid_ensure_string'>ensure_string</span>
771
+ <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='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_blank?'>blank?</span> <span class='op'>?</span> <span class='int'>1</span><span class='period'>.</span><span class='id identifier rubyid_hour'>hour</span> <span class='op'>*</span> <span class='int'>1000</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>
772
+ <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>
773
+ <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>
774
+
775
+ <span class='comment'># Wrap the final key to ensure we don't have colliding namespaces.
776
+ </span> <span class='id identifier rubyid_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:complete_key</span><span class='rbracket'>]</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_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:key</span><span class='rbracket'>]</span><span class='rbrace'>}</span><span class='tstring_content'>]</span><span class='tstring_end'>&quot;</span></span>
777
+
778
+ <span class='comment'># Compute the hash key used for referencing this value
779
+ </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_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:complete_key</span><span class='rbracket'>]</span><span class='rparen'>)</span>
780
+
781
+ <span class='id identifier rubyid_options'>options</span>
782
+ <span class='kw'>end</span></pre>
783
+ </td>
784
+ </tr>
785
+ </table>
555
786
  </div>
556
787
 
557
788
  <div class="method_details ">
@@ -565,8 +796,26 @@
565
796
 
566
797
  </h3><div class="docstring">
567
798
  <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>
799
+ <p>This is the main method of the framework.</p>
800
+
801
+ <p>It tries reading a key from the cache.</p>
802
+
803
+ <p>If it doesn&#39;t find it, it uses the provided block (which receives options as argument) to compute its value and then store it into the cache for later usages.</p>
804
+
805
+ <pre class="code ruby"><code><span class='id identifier rubyid_value'>value</span> <span class='op'>=</span> <span class='const'>Elephas</span><span class='op'>::</span><span class='const'>Cache</span><span class='period'>.</span><span class='id identifier rubyid_use'>use</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>KEY</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_options'>options</span><span class='op'>|</span>
806
+ <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>VALUE</span><span class='tstring_end'>&quot;</span></span>
807
+ <span class='kw'>end</span>
808
+
809
+ <span class='id identifier rubyid_value'>value</span>
810
+ <span class='comment'># =&gt; &quot;VALUE&quot;
811
+ </span>
812
+ <span class='id identifier rubyid_value'>value</span> <span class='op'>=</span> <span class='const'>Elephas</span><span class='op'>::</span><span class='const'>Cache</span><span class='period'>.</span><span class='id identifier rubyid_use'>use</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>KEY</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_options'>options</span><span class='op'>|</span>
813
+ <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>ANOTHER VALUE</span><span class='tstring_end'>&quot;</span></span>
814
+ <span class='kw'>end</span>
815
+
816
+ <span class='id identifier rubyid_value'>value</span>
817
+ <span class='comment'># =&gt; &quot;VALUE&quot;
818
+ </span></code></pre>
570
819
 
571
820
 
572
821
  </div>
@@ -610,32 +859,19 @@ It tries reading a key from the cache. If it doesn&#39;t find it, it uses the pr
610
859
 
611
860
  </ul>
612
861
 
862
+ <p class="tag_title">See Also:</p>
863
+ <ul class="see">
864
+
865
+ <li></li>
866
+
867
+ </ul>
868
+
613
869
  </div><table class="source_code">
614
870
  <tr>
615
871
  <td>
616
872
  <pre class="lines">
617
873
 
618
874
 
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
875
  39
640
876
  40
641
877
  41
@@ -646,38 +882,32 @@ It tries reading a key from the cache. If it doesn&#39;t find it, it uses the pr
646
882
  46
647
883
  47
648
884
  48
649
- 49</pre>
885
+ 49
886
+ 50
887
+ 51
888
+ 52
889
+ 53
890
+ 54
891
+ 55
892
+ 56</pre>
650
893
  </td>
651
894
  <td>
652
- <pre class="code"><span class="info file"># File 'lib/elephas/cache.rb', line 19</span>
895
+ <pre class="code"><span class="info file"># File 'lib/elephas/cache.rb', line 39</span>
653
896
 
654
897
  <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
898
  <span class='id identifier rubyid_rv'>rv</span> <span class='op'>=</span> <span class='kw'>nil</span>
656
899
 
657
900
  <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>
901
+ </span> <span class='id identifier rubyid_options'>options</span> <span class='op'>=</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_setup_options'>setup_options</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span>
669
902
 
670
903
  <span class='comment'># Check if the storage has the value (if we don't have to skip the cache)
671
904
  </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
905
 
673
906
  <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>
907
+ </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_options'>options</span><span class='rparen'>)</span>
908
+ <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_options'>options</span><span class='lbracket'>[</span><span class='symbol'>:complete_key</span><span class='rbracket'>]</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
909
+ </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_rv'>rv</span><span class='period'>.</span><span class='id identifier rubyid_hash'>hash</span><span class='comma'>,</span> <span class='id identifier rubyid_rv'>rv</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span> <span class='kw'>if</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_nil?'>nil?</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='comment'># We have a value and we have to store it
910
+ </span> <span class='kw'>end</span>
681
911
 
682
912
  <span class='comment'># Return value
683
913
  </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>
@@ -700,8 +930,6 @@ It tries reading a key from the cache. If it doesn&#39;t find it, it uses the pr
700
930
  <div class="discussion">
701
931
  <p>Writes a value to the cache.</p>
702
932
 
703
- <p>TODO: Insert options documentation.</p>
704
-
705
933
 
706
934
  </div>
707
935
  </div>
@@ -776,25 +1004,28 @@ It tries reading a key from the cache. If it doesn&#39;t find it, it uses the pr
776
1004
 
777
1005
  </ul>
778
1006
 
1007
+ <p class="tag_title">See Also:</p>
1008
+ <ul class="see">
1009
+
1010
+ <li><span class='object_link'><a href="#setup_options-class_method" title="Elephas::Cache.setup_options (method)">setup_options</a></span></li>
1011
+
1012
+ </ul>
1013
+
779
1014
  </div><table class="source_code">
780
1015
  <tr>
781
1016
  <td>
782
1017
  <pre class="lines">
783
1018
 
784
1019
 
785
- 66
786
- 67
787
- 68
788
- 69
789
- 70</pre>
1020
+ 73
1021
+ 74
1022
+ 75</pre>
790
1023
  </td>
791
1024
  <td>
792
- <pre class="code"><span class="info file"># File 'lib/elephas/cache.rb', line 66</span>
1025
+ <pre class="code"><span class="info file"># File 'lib/elephas/cache.rb', line 73</span>
793
1026
 
794
1027
  <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>
1028
+ <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='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_setup_options'>setup_options</span><span class='lparen'>(</span><span class='id identifier rubyid_options'>options</span><span class='comma'>,</span> <span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span><span class='rparen'>)</span>
798
1029
  <span class='kw'>end</span></pre>
799
1030
  </td>
800
1031
  </tr>
@@ -806,7 +1037,7 @@ It tries reading a key from the cache. If it doesn&#39;t find it, it uses the pr
806
1037
  </div>
807
1038
 
808
1039
  <div id="footer">
809
- Generated on Sat Jul 28 14:29:52 2012 by
1040
+ Generated on Sun Jul 29 10:32:07 2012 by
810
1041
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
811
1042
  0.8.2.1 (ruby-1.9.2).
812
1043
  </div>