zache 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/zache.rb +4 -4
- data/test/test_zache.rb +6 -3
- data/zache.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 257081764cc35a64985d251872770a52136ad5bdab0a11c6183e61af038e2eed
|
4
|
+
data.tar.gz: 8fcdeb45bdb0471b97b3706ad0c82b6779a11fc7d930b9e2d7706691f400acb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a232c9be3072ade8f8d83c647f67b85d7506cc34a2c17bd3ce6b85af5cf0cd8c5aed420d0019264ad62c73855ec28bbe7443b170f006dede7eec3d5dfb077f5
|
7
|
+
data.tar.gz: b0eb1264f9ad527ec8fa36f12b2911dfcdfb62c9add06c7de088401a546bb96836279692e7138a0e51e74c74b2f4e80b60a5e2d31007a1d9bf406463710abe91
|
data/lib/zache.rb
CHANGED
@@ -45,7 +45,7 @@ class Zache
|
|
45
45
|
# unless you really know what you are doing.
|
46
46
|
#
|
47
47
|
# If the <tt>dirty</tt> argument is set to <tt>true</tt>, a previously
|
48
|
-
# calculated result will be returned if it exists.
|
48
|
+
# calculated result will be returned if it exists and is already expired.
|
49
49
|
def initialize(sync: true, dirty: false)
|
50
50
|
@hash = {}
|
51
51
|
@sync = sync
|
@@ -60,11 +60,11 @@ class Zache
|
|
60
60
|
# key will never be expired.
|
61
61
|
#
|
62
62
|
# If the <tt>dirty</tt> argument is set to <tt>true</tt>, a previously
|
63
|
-
# calculated result will be returned if it exists.
|
63
|
+
# calculated result will be returned if it exists and is already expired.
|
64
64
|
def get(key, lifetime: 2**32, dirty: false)
|
65
65
|
if block_given?
|
66
|
-
if (dirty || @dirty) && locked? &&
|
67
|
-
return @hash[key]
|
66
|
+
if (dirty || @dirty) && locked? && key_expired?(key) && @hash.key?(key)
|
67
|
+
return @hash[key][:value]
|
68
68
|
end
|
69
69
|
synchronized { calc(key, lifetime) { yield } }
|
70
70
|
else
|
data/test/test_zache.rb
CHANGED
@@ -190,13 +190,16 @@ class ZacheTest < Minitest::Test
|
|
190
190
|
|
191
191
|
def test_returns_dirty_result
|
192
192
|
cache = Zache.new
|
193
|
-
cache.get(:
|
193
|
+
cache.get(:x, lifetime: 0) { 1 }
|
194
194
|
long = Thread.start do
|
195
|
-
cache.get(:
|
195
|
+
cache.get(:x) do
|
196
|
+
sleep 1000
|
197
|
+
2
|
198
|
+
end
|
196
199
|
end
|
197
200
|
sleep 0.1
|
198
201
|
Timeout.timeout(1) do
|
199
|
-
assert_equal(1, cache.get(:
|
202
|
+
assert_equal(1, cache.get(:x, dirty: true) { 2 })
|
200
203
|
end
|
201
204
|
long.kill
|
202
205
|
end
|
data/zache.gemspec
CHANGED
@@ -31,7 +31,7 @@ Gem::Specification.new do |s|
|
|
31
31
|
s.rubygems_version = '2.5'
|
32
32
|
s.required_ruby_version = '>=2.5'
|
33
33
|
s.name = 'zache'
|
34
|
-
s.version = '0.5.
|
34
|
+
s.version = '0.5.2'
|
35
35
|
s.license = 'MIT'
|
36
36
|
s.summary = 'In-memory Cache'
|
37
37
|
s.description = 'Zero-footprint in-memory thread-safe cache'
|