lib/zache.rb in zache-0.5.1 vs lib/zache.rb in zache-0.5.2

- old
+ new

@@ -43,11 +43,11 @@ # "sync" is whether the hash is thread-safe (`true`) # or not (`false`); it is recommended to leave this parameter untouched, # unless you really know what you are doing. # # If the <tt>dirty</tt> argument is set to <tt>true</tt>, a previously - # calculated result will be returned if it exists. + # calculated result will be returned if it exists and is already expired. def initialize(sync: true, dirty: false) @hash = {} @sync = sync @dirty = dirty @monitor = Monitor.new @@ -58,14 +58,14 @@ # the block is not given, an exception will be raised. The lifetime # must be in seconds. The default lifetime is huge, which means that the # 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. + # calculated result will be returned if it exists and is already expired. def get(key, lifetime: 2**32, dirty: false) if block_given? - if (dirty || @dirty) && locked? && !key_expired?(key) && @hash.key?(key) - return @hash[key] + 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)