Sha256: ba94bc523072dfa5e349e83b2e617cb4b233e28b7ce0296ca2b1d41fd5ba4935
Contents?: true
Size: 1.49 KB
Versions: 2
Compression:
Stored size: 1.49 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, whose valid until date has been passed # will cause inconsistency. class ValidUntil < ConsistencyGuard def consistent? if min_valid_until_known? return no_changes_since? else return current_min_valid_until.nil? end end def guard! cache.write(cache_key, current_min_valid_until) end # @return true if a timestamp can be read from cache with {#cache_key} def min_valid_until_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_until == cache.read(cache_key) && current_min_valid_until > Time.now end # @return [String] the cache key for storing {#current_min_valid_until} def cache_key component.cache_key('min_valid_until') end # @return [Time] the timestamp of the the object that will be deactivated in nearest future def current_min_valid_until str_value = RailsConnector::Obj.where('valid_until > ?', Time.now.to_iso).minimum(:valid_until) 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_until.rb |
infopark_component_cache-1.0.0 | lib/infopark_component_cache/guards/valid_until.rb |