class InfoparkComponentCache::Guards::ValidFrom
@author Tomasz Przedmojski <tomasz.przedmojski@infopark.de>
This guard ensures that any object that becomes valid (through valid_from) will cause inconsistency
Public Instance Methods
cache_key()
click to toggle source
@return [String] the cache key for storing {#current_min_valid_from}
# File lib/infopark_component_cache/guards/valid_from.rb, line 32 def cache_key component.cache_key("min_valid_from") end
consistent?()
click to toggle source
# File lib/infopark_component_cache/guards/valid_from.rb, line 9 def consistent? if min_valid_from_known? no_changes_since? else current_min_valid_from.nil? end end
current_min_valid_from()
click to toggle source
@return [Time] the timestamp of the most recent valid_from, or nil if none found
# File lib/infopark_component_cache/guards/valid_from.rb, line 37 def current_min_valid_from str_value = scoped_relation.where("valid_from > ?", Time.now.to_iso).minimum(:valid_from) return str_value if str_value.kind_of? Time RailsConnector::DateAttribute.parse(str_value) if str_value.present? end
guard!()
click to toggle source
# File lib/infopark_component_cache/guards/valid_from.rb, line 17 def guard! cache.write(cache_key, current_min_valid_from) end
min_valid_from_known?()
click to toggle source
@return true if a timestamp can be read from cache with {#cache_key}
# File lib/infopark_component_cache/guards/valid_from.rb, line 22 def min_valid_from_known? cache.exist?(cache_key) && cache.read(cache_key).kind_of?(Time) end
no_changes_since?()
click to toggle source
@return true if no obj has been changed since last {#guard!}
# File lib/infopark_component_cache/guards/valid_from.rb, line 27 def no_changes_since? current_min_valid_from == cache.read(cache_key) && current_min_valid_from > Time.now end