soft_evict_cache 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 912e5421f71f6539a095895f2c70bf94e684de48
4
- data.tar.gz: 8b98ed02d6d5785ec1159320aedf83a2dc62c3bd
3
+ metadata.gz: f57debc26500781e2a1d0c6c310759dce5e688f5
4
+ data.tar.gz: 788fad8af64a204ee9d9e29270b7d9457f3efe65
5
5
  SHA512:
6
- metadata.gz: 99621d6b03598841cd146d248ee61d1e464618f616b23698aa49d8724878ea9c379fee5baab9384375fa81e296cd5a88afdb8a8aa41283bdc00b6e166ec4ade6
7
- data.tar.gz: 7ecb5d50d08d82fb8456dfe108ef82bae7749b0b67a7b2df27682f8575de885be7d1d009989374501f8ab4a378960d3fdc47761a7d7297f83e3d67bb89d9e20c
6
+ metadata.gz: abf8e375647a3edde2b342143a54fa04035664d055a4fb9991036ed480c738c2753b7c79314957e7d1480ec0fa96339a4d50ee0fcbb42c5287903ccf7868a537
7
+ data.tar.gz: a8f5c1bc7f7e4682f0c1b1c64e00a7001bfe9054b88395f0d29acff19c22dbf589811154d8f30a61b127d09f9b9631584e12d6c5d1376d52e4336cbbdbf04769
@@ -23,10 +23,16 @@ module SoftEvictCache
23
23
  @agent = Concurrent::Agent.new(Entry.new(nil, Time.now - 1, Time.now - 1))
24
24
  end
25
25
 
26
- def update_entry(old_entry)
26
+ def update_entry(old_entry, promise = nil)
27
27
  return old_entry unless old_entry.soft_evicted?
28
28
  value = @next_value.call
29
- Entry.new(value, Time.now + @soft_evict, Time.now + @hard_evict)
29
+ entry = Entry.new(value, Time.now + @soft_evict, Time.now + @hard_evict)
30
+ promise.set(entry) if promise
31
+ entry
32
+ rescue Exception => e
33
+ promise.fail(e) if promise rescue nil
34
+ sleep(0.25) rescue nil
35
+ old_entry
30
36
  end
31
37
 
32
38
  def value
@@ -36,17 +42,8 @@ module SoftEvictCache
36
42
  current_entry.value
37
43
  else
38
44
  promise = Concurrent::Promise.new
39
- @agent.send do |old_entry|
40
- begin
41
- new_entry = update_entry(old_entry)
42
- promise.set(new_entry.value)
43
- new_entry
44
- rescue Exception => e
45
- promise.fail(e)
46
- raise e
47
- end
48
- end
49
- promise.value!
45
+ @agent.send { |old_entry| update_entry(old_entry, promise) }
46
+ promise.value!.value
50
47
  end
51
48
  end
52
49
  end
@@ -1,3 +1,3 @@
1
1
  module SoftEvictCache
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soft_evict_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tejas Dinkar
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-30 00:00:00.000000000 Z
11
+ date: 2016-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -104,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
104
  version: '0'
105
105
  requirements: []
106
106
  rubyforge_project:
107
- rubygems_version: 2.2.2
107
+ rubygems_version: 2.5.1
108
108
  signing_key:
109
109
  specification_version: 4
110
110
  summary: A Soft Evict Cache For Ruby