zache 0.10.0 → 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -2
- data/lib/zache.rb +4 -3
- data/test/test_zache.rb +12 -4
- 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: aff25777e250a00476b61b3b8ff9e9d8492546b9e4c53fbdba28f7cba3c64a95
|
4
|
+
data.tar.gz: d7f7214d2829b7e2d513fa36b0de36326d9453ad33a41f21ab64485a263c3b6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 401d5bcfb34777d3d0e0b22b0c65802bdd273eb9b3076710cfd8a31c63fa3f8f86fdda5c965f28bc599045c42fc24c187c0fa2bccb7fbd014cdfced6232bdcc1
|
7
|
+
data.tar.gz: 8993cc92f22c9941b457b8dfaa8ae86893015d996bde9ddcbc10a1459d2358310cea93097477f6f43fc7320e6e6b0f21e38a1a32fcedc1298edd0520f032dde6
|
data/.rubocop.yml
CHANGED
data/lib/zache.rb
CHANGED
@@ -95,14 +95,15 @@ class Zache
|
|
95
95
|
# If the <tt>dirty</tt> argument is set to <tt>true</tt>, a previously
|
96
96
|
# calculated result will be returned if it exists and is already expired.
|
97
97
|
def get(key, lifetime: 2**32, dirty: false)
|
98
|
-
if (dirty || @dirty) && locked? && key_expired?(key) && @hash.key?(key)
|
99
|
-
return @hash[key][:value]
|
100
|
-
end
|
101
98
|
if block_given?
|
99
|
+
if (dirty || @dirty) && locked? && key_expired?(key) && @hash.key?(key)
|
100
|
+
return @hash[key][:value]
|
101
|
+
end
|
102
102
|
synchronized { calc(key, lifetime) { yield } }
|
103
103
|
else
|
104
104
|
rec = @hash[key]
|
105
105
|
if key_expired?(key)
|
106
|
+
return rec[:value] if dirty || @dirty
|
106
107
|
@hash.delete(key)
|
107
108
|
rec = nil
|
108
109
|
end
|
data/test/test_zache.rb
CHANGED
@@ -208,7 +208,7 @@ class ZacheTest < Minitest::Test
|
|
208
208
|
end
|
209
209
|
|
210
210
|
def test_returns_dirty_result
|
211
|
-
cache = Zache.new
|
211
|
+
cache = Zache.new(dirty: true)
|
212
212
|
cache.get(:x, lifetime: 0) { 1 }
|
213
213
|
long = Thread.start do
|
214
214
|
cache.get(:x) do
|
@@ -218,13 +218,21 @@ class ZacheTest < Minitest::Test
|
|
218
218
|
end
|
219
219
|
sleep 0.1
|
220
220
|
Timeout.timeout(1) do
|
221
|
-
assert(cache.exists?(:x
|
222
|
-
assert_equal(1, cache.get(:x
|
223
|
-
assert_equal(1, cache.get(:x
|
221
|
+
assert(cache.exists?(:x))
|
222
|
+
assert_equal(1, cache.get(:x))
|
223
|
+
assert_equal(1, cache.get(:x) { 2 })
|
224
224
|
end
|
225
225
|
long.kill
|
226
226
|
end
|
227
227
|
|
228
|
+
def test_returns_dirty_result_when_not_locked
|
229
|
+
cache = Zache.new(dirty: true)
|
230
|
+
cache.get(:x, lifetime: 0) { 1 }
|
231
|
+
assert(cache.exists?(:x))
|
232
|
+
assert_equal(1, cache.get(:x))
|
233
|
+
assert_equal(2, cache.get(:x) { 2 })
|
234
|
+
end
|
235
|
+
|
228
236
|
def test_fetches_multiple_keys_in_many_threads_in_dirty_mode
|
229
237
|
cache = Zache.new(dirty: true)
|
230
238
|
set = Concurrent::Set.new
|
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.10.
|
34
|
+
s.version = '0.10.1'
|
35
35
|
s.license = 'MIT'
|
36
36
|
s.summary = 'In-memory Cache'
|
37
37
|
s.description = 'Zero-footprint in-memory thread-safe cache'
|