Class: InfoparkComponentCache::Component
- Inherits:
-
Object
- Object
- InfoparkComponentCache::Component
- Defined in:
- lib/infopark_component_cache/component.rb
Overview
Cache entity (component) consists of an obj, a name and some parameters (hash). It should be used to point to some data stored in a particular context
Instance Attribute Summary collapse
-
#component ⇒ Object
readonly
Returns the value of attribute component.
-
#obj ⇒ Object
readonly
Returns the value of attribute obj.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #cache_key(meta_prefix = nil) ⇒ Object
- #identity_hash ⇒ Object
-
#initialize(obj, component, params = {}) ⇒ Component
constructor
A new instance of Component.
- #name ⇒ Object
Constructor Details
#initialize(obj, component, params = {}) ⇒ Component
Returns a new instance of Component.
10 11 12 13 14 |
# File 'lib/infopark_component_cache/component.rb', line 10 def initialize(obj, component, params = {}) @obj = obj @component = component @params = params end |
Instance Attribute Details
#component ⇒ Object (readonly)
Returns the value of attribute component.
8 9 10 |
# File 'lib/infopark_component_cache/component.rb', line 8 def component @component end |
#obj ⇒ Object (readonly)
Returns the value of attribute obj.
8 9 10 |
# File 'lib/infopark_component_cache/component.rb', line 8 def obj @obj end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
8 9 10 |
# File 'lib/infopark_component_cache/component.rb', line 8 def params @params end |
Instance Method Details
#cache_key(meta_prefix = nil) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/infopark_component_cache/component.rb', line 20 def cache_key( = nil) if + "_" + KeyGenerator.generate_key(identity_hash) else KeyGenerator.generate_key(identity_hash) end end |
#identity_hash ⇒ Object
28 29 30 31 32 |
# File 'lib/infopark_component_cache/component.rb', line 28 def identity_hash @params .except(:obj) # avoid the (ruby) object_id as part of the cache key (to_s), because it will change for each request .merge({ obj_name: @obj.name, obj_id: @obj.id, obj_component: @component }) end |
#name ⇒ Object
16 17 18 |
# File 'lib/infopark_component_cache/component.rb', line 16 def name component end |