Sha256: 434eb1b0de4f73c4ea567f848b60f6185ef7e7fef14b5423f995a938cde736ff
Contents?: true
Size: 1.15 KB
Versions: 2
Compression:
Stored size: 1.15 KB
Contents
require "infopark_component_cache/guards/cms_state_guard" module InfoparkComponentCache module Guards # @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) class ObjCount < CmsStateGuard def consistent? count_known? && no_changes_since? end def guard! cache.write(cache_key, current_count) end # @return true if obj count can be read from cache with {#cache_key} def count_known? cache.exist?(cache_key) && cache.read(cache_key).kind_of?(Integer) end # @return true if no obj has been deleted or added since last {#guard!} def no_changes_since? current_count == cache.read(cache_key) end # @return [String] the cache key for storing {#current_count} def cache_key component.cache_key('obj_count') end # @return [Integer] the number of Objs in the database def current_count scoped_relation.count end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
infopark_component_cache-3.2.0 | lib/infopark_component_cache/guards/obj_count.rb |
infopark_component_cache-3.1.1 | lib/infopark_component_cache/guards/obj_count.rb |