lib/zache.rb in zache-0.10.0 vs lib/zache.rb in zache-0.10.1
- old
+ new
@@ -93,17 +93,18 @@
# key will never be expired.
#
# If the <tt>dirty</tt> argument is set to <tt>true</tt>, a previously
# calculated result will be returned if it exists and is already expired.
def get(key, lifetime: 2**32, dirty: false)
- if (dirty || @dirty) && locked? && key_expired?(key) && @hash.key?(key)
- return @hash[key][:value]
- end
if block_given?
+ if (dirty || @dirty) && locked? && key_expired?(key) && @hash.key?(key)
+ return @hash[key][:value]
+ end
synchronized { calc(key, lifetime) { yield } }
else
rec = @hash[key]
if key_expired?(key)
+ return rec[:value] if dirty || @dirty
@hash.delete(key)
rec = nil
end
raise 'The key is absent in the cache' if rec.nil?
rec[:value]