Class: InfoparkComponentCache::Guards::ObjCount
- Inherits:
-
CmsStateGuard
- Object
- ConsistencyGuard
- CmsStateGuard
- InfoparkComponentCache::Guards::ObjCount
- Defined in:
- lib/infopark_component_cache/guards/obj_count.rb
Overview
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)
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from ConsistencyGuard
Instance Method Summary collapse
-
#cache_key ⇒ String
The cache key for storing #current_count.
- #consistent? ⇒ Boolean
-
#count_known? ⇒ Boolean
True if obj count can be read from cache with #cache_key.
-
#current_count ⇒ Integer
The number of Objs in the database.
- #guard! ⇒ Object
-
#no_changes_since? ⇒ Boolean
True if no obj has been deleted or added since last #guard!.
Methods inherited from ConsistencyGuard
Constructor Details
This class inherits a constructor from InfoparkComponentCache::ConsistencyGuard
Instance Method Details
#cache_key ⇒ String
Returns the cache key for storing #current_count.
30 31 32 |
# File 'lib/infopark_component_cache/guards/obj_count.rb', line 30 def cache_key component.cache_key("obj_count") end |
#consistent? ⇒ Boolean
11 12 13 |
# File 'lib/infopark_component_cache/guards/obj_count.rb', line 11 def consistent? count_known? && no_changes_since? end |
#count_known? ⇒ Boolean
Returns true if obj count can be read from cache with #cache_key.
20 21 22 |
# 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 ⇒ Integer
Returns the number of Objs in the database.
35 36 37 |
# File 'lib/infopark_component_cache/guards/obj_count.rb', line 35 def current_count scoped_relation.count end |
#guard! ⇒ Object
15 16 17 |
# File 'lib/infopark_component_cache/guards/obj_count.rb', line 15 def guard! cache.write(cache_key, current_count) end |
#no_changes_since? ⇒ Boolean
Returns true if no obj has been deleted or added since last #guard!.
25 26 27 |
# File 'lib/infopark_component_cache/guards/obj_count.rb', line 25 def no_changes_since? current_count == cache.read(cache_key) end |