hashcache 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/hashcache.rb +12 -12
  2. 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
- self.write item
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
- if @file_cache == true and File.exists? @file_path + '/' + item then
26
- read_file item
27
- else
28
- val = yield
29
- @h[item] = val
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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hashcache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors: []
7
7