class InfoparkComponentCache::Guards::ObjCount
@author Tomasz Przedmojski <tomasz.przedmojski@infopark.de>
This Guard class ensures that the total count of Objs in the database does not change inbetween. (It caches the number of Objs and compares it to the current count)
Public Instance Methods
cache_key()
click to toggle source
@return [String] the cache key for storing {#current_count}
# File lib/infopark_component_cache/guards/obj_count.rb, line 30 def cache_key component.cache_key("obj_count") end
consistent?()
click to toggle source
# File lib/infopark_component_cache/guards/obj_count.rb, line 11 def consistent? count_known? && no_changes_since? end
count_known?()
click to toggle source
@return true if obj count can be read from cache with {#cache_key}
# File lib/infopark_component_cache/guards/obj_count.rb, line 20 def count_known? cache.exist?(cache_key) && cache.read(cache_key).kind_of?(Integer) end
current_count()
click to toggle source
@return [Integer] the number of Objs in the database
# File lib/infopark_component_cache/guards/obj_count.rb, line 35 def current_count scoped_relation.count end
guard!()
click to toggle source
# File lib/infopark_component_cache/guards/obj_count.rb, line 15 def guard! cache.write(cache_key, current_count) end
no_changes_since?()
click to toggle source
@return true if no obj has been deleted or added since last {#guard!}
# File lib/infopark_component_cache/guards/obj_count.rb, line 25 def no_changes_since? current_count == cache.read(cache_key) end