unicache 0.0.1 → 0.0.2

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 CHANGED
@@ -1,3 +1,5 @@
1
1
  = Version history
2
2
 
3
+ [0.0.2] Uses NotifyHub for callbacks. No user visible changes.
4
+
3
5
  [0.0.1] Initial version.
@@ -133,7 +133,7 @@
133
133
  </div>
134
134
 
135
135
  <div id="footer">
136
- Generated on Tue Dec 31 14:00:42 2013 by
136
+ Generated on Mon Feb 10 23:59:39 2014 by
137
137
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
138
138
  0.8.6.1 (ruby-1.9.3).
139
139
  </div>
@@ -129,7 +129,7 @@
129
129
  </div>
130
130
 
131
131
  <div id="footer">
132
- Generated on Tue Dec 31 14:00:42 2013 by
132
+ Generated on Mon Feb 10 23:59:39 2014 by
133
133
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
134
134
  0.8.6.1 (ruby-1.9.3).
135
135
  </div>
@@ -133,7 +133,7 @@
133
133
  </div>
134
134
 
135
135
  <div id="footer">
136
- Generated on Tue Dec 31 14:00:42 2013 by
136
+ Generated on Mon Feb 10 23:59:39 2014 by
137
137
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
138
138
  0.8.6.1 (ruby-1.9.3).
139
139
  </div>
@@ -295,13 +295,13 @@ of operations.</p>
295
295
  <pre class="lines">
296
296
 
297
297
 
298
- 311
299
- 312
300
- 313
301
- 314</pre>
298
+ 307
299
+ 308
300
+ 309
301
+ 310</pre>
302
302
  </td>
303
303
  <td>
304
- <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 311</span>
304
+ <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 307</span>
305
305
 
306
306
  <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span>
307
307
  <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>
@@ -345,14 +345,14 @@ of operations.</p>
345
345
  <pre class="lines">
346
346
 
347
347
 
348
- 318
349
- 319
350
- 320
351
- 321
352
- 322</pre>
348
+ 314
349
+ 315
350
+ 316
351
+ 317
352
+ 318</pre>
353
353
  </td>
354
354
  <td>
355
- <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 318</span>
355
+ <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 314</span>
356
356
 
357
357
  <span class='kw'>def</span> <span class='id identifier rubyid_clear'>clear</span>
358
358
  <span class='ivar'>@lock</span><span class='period'>.</span><span class='id identifier rubyid_lock'>lock</span>
@@ -390,12 +390,12 @@ of operations.</p>
390
390
  <pre class="lines">
391
391
 
392
392
 
393
- 365
394
- 366
395
- 367</pre>
393
+ 361
394
+ 362
395
+ 363</pre>
396
396
  </td>
397
397
  <td>
398
- <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 365</span>
398
+ <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 361</span>
399
399
 
400
400
  <span class='kw'>def</span> <span class='id identifier rubyid_nextEvict'>nextEvict</span>
401
401
  <span class='ivar'>@list</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span>
@@ -453,6 +453,10 @@ of operations.</p>
453
453
  <pre class="lines">
454
454
 
455
455
 
456
+ 342
457
+ 343
458
+ 344
459
+ 345
456
460
  346
457
461
  347
458
462
  348
@@ -464,14 +468,10 @@ of operations.</p>
464
468
  354
465
469
  355
466
470
  356
467
- 357
468
- 358
469
- 359
470
- 360
471
- 361</pre>
471
+ 357</pre>
472
472
  </td>
473
473
  <td>
474
- <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 346</span>
474
+ <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 342</span>
475
475
 
476
476
  <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>
477
477
  <span class='ivar'>@lock</span><span class='period'>.</span><span class='id identifier rubyid_lock'>lock</span>
@@ -536,6 +536,10 @@ of the list.</p>
536
536
  <pre class="lines">
537
537
 
538
538
 
539
+ 325
540
+ 326
541
+ 327
542
+ 328
539
543
  329
540
544
  330
541
545
  331
@@ -543,14 +547,10 @@ of the list.</p>
543
547
  333
544
548
  334
545
549
  335
546
- 336
547
- 337
548
- 338
549
- 339
550
- 340</pre>
550
+ 336</pre>
551
551
  </td>
552
552
  <td>
553
- <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 329</span>
553
+ <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 325</span>
554
554
 
555
555
  <span class='kw'>def</span> <span class='id identifier rubyid_update'>update</span><span class='lparen'>(</span> <span class='id identifier rubyid_key'>key</span> <span class='rparen'>)</span>
556
556
 
@@ -574,7 +574,7 @@ of the list.</p>
574
574
  </div>
575
575
 
576
576
  <div id="footer">
577
- Generated on Tue Dec 31 14:00:42 2013 by
577
+ Generated on Mon Feb 10 23:59:39 2014 by
578
578
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
579
579
  0.8.6.1 (ruby-1.9.3).
580
580
  </div>
@@ -133,7 +133,7 @@
133
133
  </div>
134
134
 
135
135
  <div id="footer">
136
- Generated on Tue Dec 31 14:00:42 2013 by
136
+ Generated on Mon Feb 10 23:59:39 2014 by
137
137
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
138
138
  0.8.6.1 (ruby-1.9.3).
139
139
  </div>
@@ -133,7 +133,7 @@
133
133
  </div>
134
134
 
135
135
  <div id="footer">
136
- Generated on Tue Dec 31 14:00:42 2013 by
136
+ Generated on Mon Feb 10 23:59:39 2014 by
137
137
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
138
138
  0.8.6.1 (ruby-1.9.3).
139
139
  </div>
data/doc/UniCache.html CHANGED
@@ -713,10 +713,6 @@ Miss: 2:&lt;NA&gt;</code></pre>
713
713
  <pre class="lines">
714
714
 
715
715
 
716
- 68
717
- 69
718
- 70
719
- 71
720
716
  72
721
717
  73
722
718
  74
@@ -730,14 +726,10 @@ Miss: 2:&lt;NA&gt;</code></pre>
730
726
  82
731
727
  83
732
728
  84
733
- 85
734
- 86
735
- 87
736
- 88
737
- 89</pre>
729
+ 85</pre>
738
730
  </td>
739
731
  <td>
740
- <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 68</span>
732
+ <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 72</span>
741
733
 
742
734
  <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
735
  <span class='kw'>super</span><span class='lparen'>(</span><span class='rparen'>)</span>
@@ -748,18 +740,10 @@ Miss: 2:&lt;NA&gt;</code></pre>
748
740
 
749
741
  <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
742
 
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
-
743
+ <span class='ivar'>@cb</span> <span class='op'>=</span> <span class='const'>NotifyHub</span><span class='period'>.</span><span class='id identifier rubyid_declare'>declare</span><span class='lparen'>(</span> <span class='symbol'>:getdata</span><span class='comma'>,</span>
744
+ <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>
745
+ <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>
746
+ <span class='symbol'>:peek</span> <span class='rparen'>)</span>
763
747
  <span class='kw'>end</span></pre>
764
748
  </td>
765
749
  </tr>
@@ -799,12 +783,12 @@ Miss: 2:&lt;NA&gt;</code></pre>
799
783
  <pre class="lines">
800
784
 
801
785
 
802
- 62
803
- 63
804
- 64</pre>
786
+ 65
787
+ 66
788
+ 67</pre>
805
789
  </td>
806
790
  <td>
807
- <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 62</span>
791
+ <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 65</span>
808
792
 
809
793
  <span class='kw'>def</span> <span class='id identifier rubyid_lock'>lock</span>
810
794
  <span class='ivar'>@lock</span>
@@ -842,12 +826,12 @@ Miss: 2:&lt;NA&gt;</code></pre>
842
826
  <pre class="lines">
843
827
 
844
828
 
845
- 59
846
- 60
847
- 61</pre>
829
+ 62
830
+ 63
831
+ 64</pre>
848
832
  </td>
849
833
  <td>
850
- <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 59</span>
834
+ <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 62</span>
851
835
 
852
836
  <span class='kw'>def</span> <span class='id identifier rubyid_size'>size</span>
853
837
  <span class='ivar'>@size</span>
@@ -890,12 +874,12 @@ Miss: 2:&lt;NA&gt;</code></pre>
890
874
  <pre class="lines">
891
875
 
892
876
 
893
- 162
894
- 163
895
- 164</pre>
877
+ 158
878
+ 159
879
+ 160</pre>
896
880
  </td>
897
881
  <td>
898
- <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 162</span>
882
+ <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 158</span>
899
883
 
900
884
  <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
885
  <span class='id identifier rubyid_get'>get</span><span class='lparen'>(</span> <span class='id identifier rubyid_key'>key</span> <span class='rparen'>)</span>
@@ -931,12 +915,12 @@ Miss: 2:&lt;NA&gt;</code></pre>
931
915
  <pre class="lines">
932
916
 
933
917
 
934
- 137
935
- 138
936
- 139</pre>
918
+ 133
919
+ 134
920
+ 135</pre>
937
921
  </td>
938
922
  <td>
939
- <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 137</span>
923
+ <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 133</span>
940
924
 
941
925
  <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
926
  <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>
@@ -972,17 +956,17 @@ Miss: 2:&lt;NA&gt;</code></pre>
972
956
  <pre class="lines">
973
957
 
974
958
 
959
+ 283
960
+ 284
961
+ 285
962
+ 286
975
963
  287
976
964
  288
977
965
  289
978
- 290
979
- 291
980
- 292
981
- 293
982
- 294</pre>
966
+ 290</pre>
983
967
  </td>
984
968
  <td>
985
- <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 287</span>
969
+ <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 283</span>
986
970
 
987
971
  <span class='kw'>def</span> <span class='id identifier rubyid_clear'>clear</span>
988
972
  <span class='ivar'>@lock</span><span class='period'>.</span><span class='id identifier rubyid_lock'>lock</span>
@@ -1057,16 +1041,16 @@ peek CB is run.</p>
1057
1041
  <pre class="lines">
1058
1042
 
1059
1043
 
1044
+ 176
1045
+ 177
1046
+ 178
1047
+ 179
1060
1048
  180
1061
1049
  181
1062
- 182
1063
- 183
1064
- 184
1065
- 185
1066
- 186</pre>
1050
+ 182</pre>
1067
1051
  </td>
1068
1052
  <td>
1069
- <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 180</span>
1053
+ <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 176</span>
1070
1054
 
1071
1055
  <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
1056
  <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>
@@ -1150,15 +1134,15 @@ used, also when nil. UniCache lock is released before callback is called.</p>
1150
1134
  <pre class="lines">
1151
1135
 
1152
1136
 
1137
+ 149
1138
+ 150
1139
+ 151
1140
+ 152
1153
1141
  153
1154
- 154
1155
- 155
1156
- 156
1157
- 157
1158
- 158</pre>
1142
+ 154</pre>
1159
1143
  </td>
1160
1144
  <td>
1161
- <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 153</span>
1145
+ <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 149</span>
1162
1146
 
1163
1147
  <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'>&amp;</span><span class='id identifier rubyid_blk'>blk</span> <span class='rparen'>)</span>
1164
1148
  <span class='ivar'>@lock</span><span class='period'>.</span><span class='id identifier rubyid_lock'>lock</span>
@@ -1186,10 +1170,10 @@ used, also when nil. UniCache lock is released before callback is called.</p>
1186
1170
  <pre class="lines">
1187
1171
 
1188
1172
 
1189
- 101</pre>
1173
+ 97</pre>
1190
1174
  </td>
1191
1175
  <td>
1192
- <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 101</span>
1176
+ <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 97</span>
1193
1177
 
1194
1178
  <span class='kw'>alias</span> <span class='symbol'>:hash_get_op</span> <span class='symbol'>:[]</span></pre>
1195
1179
  </td>
@@ -1212,10 +1196,10 @@ used, also when nil. UniCache lock is released before callback is called.</p>
1212
1196
  <pre class="lines">
1213
1197
 
1214
1198
 
1215
- 100</pre>
1199
+ 96</pre>
1216
1200
  </td>
1217
1201
  <td>
1218
- <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 100</span>
1202
+ <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 96</span>
1219
1203
 
1220
1204
  <span class='kw'>alias</span> <span class='symbol'>:hash_set_op</span> <span class='symbol'>:[]=</span></pre>
1221
1205
  </td>
@@ -1238,10 +1222,10 @@ used, also when nil. UniCache lock is released before callback is called.</p>
1238
1222
  <pre class="lines">
1239
1223
 
1240
1224
 
1241
- 103</pre>
1225
+ 99</pre>
1242
1226
  </td>
1243
1227
  <td>
1244
- <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 103</span>
1228
+ <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 99</span>
1245
1229
 
1246
1230
  <span class='kw'>alias</span> <span class='symbol'>:hash_store</span> <span class='symbol'>:store</span></pre>
1247
1231
  </td>
@@ -1295,13 +1279,13 @@ used, also when nil. UniCache lock is released before callback is called.</p>
1295
1279
  <pre class="lines">
1296
1280
 
1297
1281
 
1298
- 170
1299
- 171
1300
- 172
1301
- 173</pre>
1282
+ 166
1283
+ 167
1284
+ 168
1285
+ 169</pre>
1302
1286
  </td>
1303
1287
  <td>
1304
- <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 170</span>
1288
+ <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 166</span>
1305
1289
 
1306
1290
  <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
1291
  <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>
@@ -1374,15 +1358,15 @@ used, also when nil. UniCache lock is released before callback is called.</p>
1374
1358
  <pre class="lines">
1375
1359
 
1376
1360
 
1361
+ 124
1362
+ 125
1363
+ 126
1364
+ 127
1377
1365
  128
1378
- 129
1379
- 130
1380
- 131
1381
- 132
1382
- 133</pre>
1366
+ 129</pre>
1383
1367
  </td>
1384
1368
  <td>
1385
- <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 128</span>
1369
+ <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 124</span>
1386
1370
 
1387
1371
  <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
1372
  <span class='ivar'>@lock</span><span class='period'>.</span><span class='id identifier rubyid_lock'>lock</span>
@@ -1502,21 +1486,21 @@ entry.</p>
1502
1486
  <pre class="lines">
1503
1487
 
1504
1488
 
1489
+ 259
1490
+ 260
1491
+ 261
1492
+ 262
1505
1493
  263
1506
1494
  264
1507
- 265
1508
- 266
1509
- 267
1510
- 268
1511
- 269</pre>
1495
+ 265</pre>
1512
1496
  </td>
1513
1497
  <td>
1514
- <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 263</span>
1498
+ <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 259</span>
1515
1499
 
1516
1500
  <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'>&amp;&amp;</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>
1501
+ <span class='kw'>begin</span>
1502
+ <span class='ivar'>@cb</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_action'>action</span><span class='lparen'>(</span> <span class='op'>&amp;</span><span class='id identifier rubyid_proc'>proc</span> <span class='rparen'>)</span>
1503
+ <span class='kw'>rescue</span>
1520
1504
  <span class='id identifier rubyid_raise'>raise</span> <span class='const'>CallbackError</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>UniCache: Trying to register invalid callback...</span><span class='tstring_end'>&quot;</span></span>
1521
1505
  <span class='kw'>end</span>
1522
1506
  <span class='kw'>end</span></pre>
@@ -1591,15 +1575,15 @@ entry.</p>
1591
1575
  <pre class="lines">
1592
1576
 
1593
1577
 
1578
+ 189
1579
+ 190
1580
+ 191
1581
+ 192
1594
1582
  193
1595
- 194
1596
- 195
1597
- 196
1598
- 197
1599
- 198</pre>
1583
+ 194</pre>
1600
1584
  </td>
1601
1585
  <td>
1602
- <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 193</span>
1586
+ <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 189</span>
1603
1587
 
1604
1588
  <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
1589
  <span class='ivar'>@lock</span><span class='period'>.</span><span class='id identifier rubyid_lock'>lock</span>
@@ -1660,25 +1644,25 @@ entry.</p>
1660
1644
  <pre class="lines">
1661
1645
 
1662
1646
 
1647
+ 271
1648
+ 272
1649
+ 273
1650
+ 274
1663
1651
  275
1664
1652
  276
1665
1653
  277
1666
1654
  278
1667
- 279
1668
- 280
1669
- 281
1670
- 282
1671
- 283</pre>
1655
+ 279</pre>
1672
1656
  </td>
1673
1657
  <td>
1674
- <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 275</span>
1658
+ <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 271</span>
1675
1659
 
1676
1660
  <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
1661
  <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>
1662
+ <span class='ivar'>@cb</span><span class='period'>.</span><span class='id identifier rubyid_remove'>remove</span><span class='lparen'>(</span> <span class='id identifier rubyid_type'>type</span> <span class='rparen'>)</span>
1679
1663
  <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>
1664
+ <span class='ivar'>@cb</span><span class='period'>.</span><span class='id identifier rubyid_ids'>ids</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_id'>id</span><span class='op'>|</span>
1665
+ <span class='ivar'>@cb</span><span class='lbracket'>[</span><span class='id identifier rubyid_id'>id</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_remove'>remove</span>
1682
1666
  <span class='kw'>end</span>
1683
1667
  <span class='kw'>end</span>
1684
1668
  <span class='kw'>end</span></pre>
@@ -1746,6 +1730,10 @@ entry.</p>
1746
1730
  <pre class="lines">
1747
1731
 
1748
1732
 
1733
+ 200
1734
+ 201
1735
+ 202
1736
+ 203
1749
1737
  204
1750
1738
  205
1751
1739
  206
@@ -1760,14 +1748,10 @@ entry.</p>
1760
1748
  215
1761
1749
  216
1762
1750
  217
1763
- 218
1764
- 219
1765
- 220
1766
- 221
1767
- 222</pre>
1751
+ 218</pre>
1768
1752
  </td>
1769
1753
  <td>
1770
- <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 204</span>
1754
+ <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 200</span>
1771
1755
 
1772
1756
  <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
1757
 
@@ -1839,12 +1823,12 @@ entry.</p>
1839
1823
  <pre class="lines">
1840
1824
 
1841
1825
 
1842
- 95
1843
- 96
1844
- 97</pre>
1826
+ 91
1827
+ 92
1828
+ 93</pre>
1845
1829
  </td>
1846
1830
  <td>
1847
- <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 95</span>
1831
+ <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 91</span>
1848
1832
 
1849
1833
  <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
1834
  <span class='ivar'>@evict</span> <span class='op'>=</span> <span class='id identifier rubyid_evict'>evict</span>
@@ -1880,10 +1864,10 @@ entry.</p>
1880
1864
  <pre class="lines">
1881
1865
 
1882
1866
 
1883
- 117</pre>
1867
+ 113</pre>
1884
1868
  </td>
1885
1869
  <td>
1886
- <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 117</span>
1870
+ <pre class="code"><span class="info file"># File 'lib/unicache.rb', line 113</span>
1887
1871
 
1888
1872
  <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
1873
  </td>
@@ -1896,7 +1880,7 @@ entry.</p>
1896
1880
  </div>
1897
1881
 
1898
1882
  <div id="footer">
1899
- Generated on Tue Dec 31 14:00:42 2013 by
1883
+ Generated on Mon Feb 10 23:59:39 2014 by
1900
1884
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
1901
1885
  0.8.6.1 (ruby-1.9.3).
1902
1886
  </div>
data/doc/_index.html CHANGED
@@ -194,7 +194,7 @@
194
194
  </div>
195
195
 
196
196
  <div id="footer">
197
- Generated on Tue Dec 31 14:00:42 2013 by
197
+ Generated on Mon Feb 10 23:59:39 2014 by
198
198
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
199
199
  0.8.6.1 (ruby-1.9.3).
200
200
  </div>
@@ -63,14 +63,17 @@
63
63
 
64
64
  <div id="content"><div id='filecontents'>
65
65
  <h1>Version history</h1>
66
- <dl class="rdoc-list"><dt>0.0.1</dt>
66
+ <dl class="rdoc-list"><dt>0.0.2</dt>
67
+ <dd>
68
+ <p>Uses NotifyHub for callbacks. No user visible changes.</p>
69
+ </dd><dt>0.0.1</dt>
67
70
  <dd>
68
71
  <p>Initial version.</p>
69
72
  </dd></dl>
70
73
  </div></div>
71
74
 
72
75
  <div id="footer">
73
- Generated on Tue Dec 31 14:00:42 2013 by
76
+ Generated on Mon Feb 10 23:59:39 2014 by
74
77
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
75
78
  0.8.6.1 (ruby-1.9.3).
76
79
  </div>
data/doc/file.README.html CHANGED
@@ -79,7 +79,7 @@ policy by default. Cache can be configured to use another policy.</p>
79
79
  </div></div>
80
80
 
81
81
  <div id="footer">
82
- Generated on Tue Dec 31 14:00:42 2013 by
82
+ Generated on Mon Feb 10 23:59:39 2014 by
83
83
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
84
84
  0.8.6.1 (ruby-1.9.3).
85
85
  </div>
data/doc/index.html CHANGED
@@ -79,7 +79,7 @@ policy by default. Cache can be configured to use another policy.</p>
79
79
  </div></div>
80
80
 
81
81
  <div id="footer">
82
- Generated on Tue Dec 31 14:00:42 2013 by
82
+ Generated on Mon Feb 10 23:59:39 2014 by
83
83
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
84
84
  0.8.6.1 (ruby-1.9.3).
85
85
  </div>
@@ -103,7 +103,7 @@
103
103
  </div>
104
104
 
105
105
  <div id="footer">
106
- Generated on Tue Dec 31 14:00:42 2013 by
106
+ Generated on Mon Feb 10 23:59:39 2014 by
107
107
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
108
108
  0.8.6.1 (ruby-1.9.3).
109
109
  </div>
data/lib/unicache.rb CHANGED
@@ -39,6 +39,9 @@
39
39
 
40
40
  class UniCache < Hash
41
41
 
42
+ require 'notifyhub'
43
+
44
+
42
45
  # Generic UniCache exception.
43
46
  class Error < StandardError; end
44
47
 
@@ -61,6 +64,7 @@ class UniCache < Hash
61
64
  # Access lock.
62
65
  attr_reader :lock
63
66
 
67
+
64
68
  # Cache initialization.
65
69
  #
66
70
  # @param size [Integer] Cache size.
@@ -74,18 +78,10 @@ class UniCache < Hash
74
78
 
75
79
  setEviction( evict )
76
80
 
77
- # See: registerCallback.
78
- @callbacks = {}
79
-
80
- @callbackType = [ :getdata,
81
- :add, :replace, :put, :overwrite,
82
- :remove, :valueremove, :hit, :miss,
83
- :peek ]
84
-
85
- @callbackType.each do |type|
86
- @callbacks[ type ] = []
87
- end
88
-
81
+ @cb = NotifyHub.declare( :getdata,
82
+ :add, :replace, :put, :overwrite,
83
+ :remove, :valueremove, :hit, :miss,
84
+ :peek )
89
85
  end
90
86
 
91
87
 
@@ -261,9 +257,9 @@ class UniCache < Hash
261
257
  # @param type [Symbol] Callback event.
262
258
  # @param proc [Proc] Callback called with args: <key>, <value>, <self>.
263
259
  def registerCallback( type, proc )
264
- if proc.kind_of?( Proc ) && @callbackType.index( type )
265
- @callbacks[ type ].push proc
266
- else
260
+ begin
261
+ @cb[ type ].action( &proc )
262
+ rescue
267
263
  raise CallbackError, "UniCache: Trying to register invalid callback..."
268
264
  end
269
265
  end
@@ -274,10 +270,10 @@ class UniCache < Hash
274
270
  # @param type [Symbol] Remove callback by type.
275
271
  def removeCallback( type = nil )
276
272
  if type
277
- @callbacks[ type ] = []
273
+ @cb.remove( type )
278
274
  else
279
- @callbackType.each do |type|
280
- @callbacks[ type ] = []
275
+ @cb.ids.each do |id|
276
+ @cb[id].remove
281
277
  end
282
278
  end
283
279
  end
@@ -419,9 +415,9 @@ class UniCache < Hash
419
415
 
420
416
  runCallbacks( :miss, key, nil )
421
417
 
422
- unless @callbacks[ :getdata ].empty?
418
+ if @cb[ :getdata ][0]
423
419
 
424
- # Get value using callback.
420
+ # Get value using callback.
425
421
 
426
422
  @lock.unlock if @lock.locked?
427
423
  ret = runCallbacks( :getdata, key, nil )
@@ -478,21 +474,10 @@ class UniCache < Hash
478
474
 
479
475
  # Run all callbacks per type.
480
476
  def runCallbacks( type, key, value = nil )
481
- ret = nil
482
- @callbacks[ type ].each do |i|
483
- ret = callback( i, key, value )
484
- end
485
- ret
486
- end
487
-
488
-
489
- # Run given callback.
490
- def callback( cb, key, value = nil )
491
477
  unless value
492
478
  value = hash_fetch( key, nil )
493
479
  end
494
- cb.call( key, value, self ) if cb
480
+ @cb[ type ].notify( key, value, self )
495
481
  end
496
482
 
497
-
498
483
  end
data/test/test_all.rb CHANGED
@@ -2,12 +2,10 @@ require 'test/unit'
2
2
  require 'unicache'
3
3
 
4
4
  class TestableUniCache < UniCache
5
- attr_reader :callbackType
6
- attr_reader :callbacks
5
+ attr_reader :cb
7
6
  attr_accessor :cb_table
8
7
  end
9
8
 
10
-
11
9
  class UniCacheTest < Test::Unit::TestCase
12
10
 
13
11
  def test_put_get
@@ -157,7 +155,7 @@ class UniCacheTest < Test::Unit::TestCase
157
155
  c.cb_table = {}
158
156
 
159
157
  # Register dummy callbacks.
160
- c.callbackType.each do |type|
158
+ c.cb.ids.each do |type|
161
159
  eval "c.registerCallback( :#{type.to_s}, Proc.new{ |k,v,o| o.cb_table[ :#{type.to_s} ] = [ k, v ] } )"
162
160
  end
163
161
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unicache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-31 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2014-02-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: notifyhub
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.0.2
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.0.2
14
30
  description: ! 'UniCache is a universal purpose cache with Least Recently Used
15
31
 
16
32
  replacement policy by default. Cache can be configured to use another policy. UniCache