Class: InfoparkComponentCache::Component

Inherits:
Object
  • Object
show all
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

Author:

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#componentObject (readonly)

Returns the value of attribute component.



8
9
10
# File 'lib/infopark_component_cache/component.rb', line 8

def component
  @component
end

#objObject (readonly)

Returns the value of attribute obj.



8
9
10
# File 'lib/infopark_component_cache/component.rb', line 8

def obj
  @obj
end

#paramsObject (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(meta_prefix = nil)
  if meta_prefix
    meta_prefix + "_" + KeyGenerator.generate_key(identity_hash)
  else
    KeyGenerator.generate_key(identity_hash)
  end
end

#identity_hashObject



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

#nameObject



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

def name
  component
end