Class: InfoparkComponentCache::ConsistencyGuard Abstract
- Inherits:
-
Object
- Object
- InfoparkComponentCache::ConsistencyGuard
- Defined in:
- lib/infopark_component_cache/consistency_guard.rb
Overview
This is abstract base class for any Cache Guards. Any class inheriting ConsistencyGuard should implement #consistent? and #guard!
Cache Guard is a class that promises some consistency, for example that no changes to the database accured between calls to #guard! and #consistent?
This consistency is crucial for the function of cache, because inconsistent cache is (automatically) invalidated.
Direct Known Subclasses
Guards::AlwaysConsistent, Guards::LastChanged, Guards::NeverConsistent, Guards::ObjCount, Guards::ValidFrom, Guards::ValidUntil, Guards::ValuePresent
Instance Attribute Summary collapse
-
#component ⇒ Object
readonly
Returns the value of attribute component.
Instance Method Summary collapse
-
#cache ⇒ CacheStorage
Instance of CacheStorage.
-
#consistent? ⇒ Boolean
abstract
This method returns true if the consistenty guarded by this class is fulfilled and false otherwise.
-
#guard! ⇒ Object
abstract
This method is called whenever cache is updated for the component.
-
#initialize(component) ⇒ ConsistencyGuard
constructor
A new instance of ConsistencyGuard.
Constructor Details
#initialize(component) ⇒ ConsistencyGuard
Returns a new instance of ConsistencyGuard.
20 21 22 |
# File 'lib/infopark_component_cache/consistency_guard.rb', line 20 def initialize(component) @component = component end |
Instance Attribute Details
#component ⇒ Object (readonly)
Returns the value of attribute component.
18 19 20 |
# File 'lib/infopark_component_cache/consistency_guard.rb', line 18 def component @component end |
Instance Method Details
#cache ⇒ CacheStorage
Returns instance of CacheStorage.
25 26 27 |
# File 'lib/infopark_component_cache/consistency_guard.rb', line 25 def cache CacheStorage.instance end |
#consistent? ⇒ Boolean
This method returns true if the consistenty guarded by this class is fulfilled and false otherwise.
32 33 34 |
# File 'lib/infopark_component_cache/consistency_guard.rb', line 32 def consistent? raise TypeError, "Abstract method consistent? called" end |
#guard! ⇒ Object
This method is called whenever cache is updated for the component. Any values checked by #consistent? can be persisted here. Use ##cache for persistence but mind the possible inconsistencies.
40 41 42 |
# File 'lib/infopark_component_cache/consistency_guard.rb', line 40 def guard! raise TypeError, "Abstract method guard! called" end |