Class: InfoparkComponentCache::ConsistencyGuard Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/infopark_component_cache/consistency_guard.rb

Overview

This class is abstract.

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.

Author:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(component, options = {}) ⇒ ConsistencyGuard

Returns a new instance of ConsistencyGuard.



18
19
20
21
# File 'lib/infopark_component_cache/consistency_guard.rb', line 18

def initialize(component, options = {})
  @component = component
  @options   = options
end

Instance Attribute Details

#componentObject (readonly)

Returns the value of attribute component.



16
17
18
# File 'lib/infopark_component_cache/consistency_guard.rb', line 16

def component
  @component
end

#optionsObject (readonly)

Returns the value of attribute options.



16
17
18
# File 'lib/infopark_component_cache/consistency_guard.rb', line 16

def options
  @options
end

Instance Method Details

#cacheCacheStorage

Returns instance of CacheStorage.

Returns:



24
25
26
# File 'lib/infopark_component_cache/consistency_guard.rb', line 24

def cache
  CacheStorage.instance
end

#consistent?Boolean

This method is abstract.

This method returns true if the consistenty guarded by this class is fulfilled and false otherwise.

Returns:

  • (Boolean)

Raises:

  • (TypeError)


31
32
33
# File 'lib/infopark_component_cache/consistency_guard.rb', line 31

def consistent?
  raise TypeError, "Abstract method consistent? called"
end

#guard!Object

This method is abstract.

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.

Raises:

  • (TypeError)


39
40
41
# File 'lib/infopark_component_cache/consistency_guard.rb', line 39

def guard!
  raise TypeError, "Abstract method guard! called"
end