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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8dc54638fe09360b05870981cc7b8ede8697aa4aba65121a33da31a23a65f339
4
- data.tar.gz: 3ba83d9a9231b3facc5faf87409a4c61ab6b9638a37bcd2a29a435965e4e530d
3
+ metadata.gz: 257081764cc35a64985d251872770a52136ad5bdab0a11c6183e61af038e2eed
4
+ data.tar.gz: 8fcdeb45bdb0471b97b3706ad0c82b6779a11fc7d930b9e2d7706691f400acb1
5
5
  SHA512:
6
- metadata.gz: bf689543044621801b55f6bc9800dcb5cb7f9f38193d6872485f5551cfec85957207184d24113707a39c36fae1ce1ba54a5be0b432f61077e352a7c88adc334e
7
- data.tar.gz: 555f8d872a9ff2780cc75a9c8f782d8fdf381ad8dce75020c58183644295ffe4b2417ba4285193d02a5bd16288920e94c3b3d8512865916abaa255106cb91e1d
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? && !key_expired?(key) && @hash.key?(key)
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(:first, lifetime: 10) { 1 }
193
+ cache.get(:x, lifetime: 0) { 1 }
194
194
  long = Thread.start do
195
- cache.get(:first) { sleep 1000 }
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(:first, dirty: true) { 2 })
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.1'
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'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko