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 +4 -4
- data/lib/soft_evict_cache/single_value_cache.rb +10 -13
- data/lib/soft_evict_cache/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f57debc26500781e2a1d0c6c310759dce5e688f5
|
4
|
+
data.tar.gz: 788fad8af64a204ee9d9e29270b7d9457f3efe65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
40
|
-
|
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
|
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.
|
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-
|
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.
|
107
|
+
rubygems_version: 2.5.1
|
108
108
|
signing_key:
|
109
109
|
specification_version: 4
|
110
110
|
summary: A Soft Evict Cache For Ruby
|