class InfoparkComponentCache::Guards::LastChanged

@author Tomasz Przedmojski <tomasz.przedmojski@infopark.de>

This Guard class ensures that the objects in database do not change inbetween. (It caches the newest timestamp and compares it to the current value)

Public Instance Methods

cache_key() click to toggle source

@return [String] the cache key for storing {#current_last_changed}

# File lib/infopark_component_cache/guards/last_changed.rb, line 29
def cache_key
  component.cache_key("last_changed")
end
consistent?() click to toggle source
# File lib/infopark_component_cache/guards/last_changed.rb, line 10
def consistent?
  last_changed_known? && no_changes_since?
end
current_last_changed() click to toggle source

@return [Time] the timestamp of the most recent change to any Obj

# File lib/infopark_component_cache/guards/last_changed.rb, line 34
def current_last_changed
  str_value = scoped_relation.maximum(:last_changed)
  return str_value if str_value.kind_of? Time

  RailsConnector::DateAttribute.parse(str_value)
end
guard!() click to toggle source
# File lib/infopark_component_cache/guards/last_changed.rb, line 14
def guard!
  cache.write(cache_key, current_last_changed)
end
last_changed_known?() click to toggle source

@return true if a timestamp can be read from cache with {#cache_key}

# File lib/infopark_component_cache/guards/last_changed.rb, line 19
def last_changed_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/last_changed.rb, line 24
def no_changes_since?
  current_last_changed <= cache.read(cache_key)
end