Sha256: 863c55cdb954ee73c8e32ae6928f0e40d3374df59166f33e1f0c9e0b70fb29d7

Contents?: true

Size: 813 Bytes

Versions: 2

Compression:

Stored size: 813 Bytes

Contents

require 'infopark_component_cache/key_generator'

module InfoparkComponentCache
  # @author Tomasz Przedmojski <tomasz.przedmojski@infopark.de>
  #
  # 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
  class Component
    attr_reader :obj, :name, :params

    def initialize(obj, component, params={})
      @obj, @component, @params = obj, component, params
    end

    def cache_key(meta_prefix=nil)
      if meta_prefix
        meta_prefix + "_" + KeyGenerator.generate_key(identity_hash)
      else
        KeyGenerator.generate_key(identity_hash)
      end
    end

    def identity_hash
      @params.merge({:obj_name=>@obj.name, :obj_id=>@obj.id, :obj_component=>@component})
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
infopark_component_cache-1.1.0 lib/infopark_component_cache/component.rb
infopark_component_cache-1.0.0 lib/infopark_component_cache/component.rb