Sha256: 1d3f0d267225fa7bf623b2bcece7203562c35ddb5ce0e073cd8421000405ee84
Contents?: true
Size: 1.47 KB
Versions: 2
Compression:
Stored size: 1.47 KB
Contents
require 'infopark_component_cache/consistency_guard' module InfoparkComponentCache module Guards # @author Tomasz Przedmojski <tomasz.przedmojski@infopark.de> # # This guard ensures that any object that becomes valid (through valid_from) # will cause inconsistency class ValidFrom < ConsistencyGuard def consistent? if min_valid_from_known? return no_changes_since? else return current_min_valid_from.nil? end end def guard! cache.write(cache_key, current_min_valid_from) end # @return true if a timestamp can be read from cache with {#cache_key} def min_valid_from_known? cache.exist?(cache_key) && cache.read(cache_key).kind_of?(Time) end # @return true if no obj has been changed since last {#guard!} def no_changes_since? current_min_valid_from == cache.read(cache_key) && current_min_valid_from > Time.now end # @return [String] the cache key for storing {#current_min_valid_from} def cache_key component.cache_key('min_valid_from') end # @return [Time] the timestamp of the most recent valid_from, or nil if none found def current_min_valid_from str_value = RailsConnector::Obj.where('valid_from > ?', Time.now.to_iso).minimum(:valid_from) if str_value.present? RailsConnector::DateAttribute.parse(str_value) else nil end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
infopark_component_cache-1.1.0 | lib/infopark_component_cache/guards/valid_from.rb |
infopark_component_cache-1.0.0 | lib/infopark_component_cache/guards/valid_from.rb |