hashcache 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/hashcache.rb +12 -12
- metadata +1 -1
data/lib/hashcache.rb
CHANGED
@@ -13,24 +13,24 @@ class HashCache
|
|
13
13
|
@h = {}
|
14
14
|
end
|
15
15
|
|
16
|
-
def read(item)
|
16
|
+
def read(item, &blk)
|
17
17
|
if @h.include? item then
|
18
18
|
self.refresh item
|
19
19
|
else
|
20
|
-
|
20
|
+
if @file_cache == true and File.exists? @file_path + '/' + item then
|
21
|
+
read_file item
|
22
|
+
else
|
23
|
+
self.write item, blk
|
24
|
+
end
|
21
25
|
end
|
22
26
|
end
|
23
27
|
|
24
|
-
def write(item)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
@h.shift if @h.length > @size
|
31
|
-
write_file(item, val) if @file_cache == true
|
32
|
-
val
|
33
|
-
end
|
28
|
+
def write(item, &blk)
|
29
|
+
val = blk.call
|
30
|
+
@h[item] = val
|
31
|
+
@h.shift if @h.length > @size
|
32
|
+
write_file(item, val) if @file_cache == true
|
33
|
+
val
|
34
34
|
end
|
35
35
|
|
36
36
|
def refresh(item)
|