Module: IdentityCache::CacheKeyGeneration

Extended by:
ActiveSupport::Concern
Defined in:
lib/identity_cache/cache_key_generation.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#attribute_cache_key_for_attribute_and_previous_values(attribute, fields) ⇒ Object

:nodoc:



41
42
43
# File 'lib/identity_cache/cache_key_generation.rb', line 41

def attribute_cache_key_for_attribute_and_previous_values(attribute, fields) # :nodoc:
  self.class.rails_cache_key_for_attribute_and_fields_and_values(attribute, fields, old_values_for_fields(fields))
end

#old_values_for_fields(fields) ⇒ Object

:nodoc:



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/identity_cache/cache_key_generation.rb', line 45

def old_values_for_fields(fields) # :nodoc:
  fields.map do |field|
    field_string = field.to_s
    if destroyed? && transaction_changed_attributes.has_key?(field_string)
      transaction_changed_attributes[field_string]
    elsif persisted? && transaction_changed_attributes.has_key?(field_string)
      transaction_changed_attributes[field_string]
    else
      self.send(field)
    end
  end
end

#primary_cache_index_keyObject

:nodoc:



29
30
31
# File 'lib/identity_cache/cache_key_generation.rb', line 29

def primary_cache_index_key # :nodoc:
  self.class.rails_cache_key(id)
end

#secondary_cache_index_key_for_current_values(fields) ⇒ Object

:nodoc:



33
34
35
# File 'lib/identity_cache/cache_key_generation.rb', line 33

def secondary_cache_index_key_for_current_values(fields) # :nodoc:
  self.class.rails_cache_index_key_for_fields_and_values(fields, fields.collect {|field| self.send(field)})
end

#secondary_cache_index_key_for_previous_values(fields) ⇒ Object

:nodoc:



37
38
39
# File 'lib/identity_cache/cache_key_generation.rb', line 37

def secondary_cache_index_key_for_previous_values(fields) # :nodoc:
  self.class.rails_cache_index_key_for_fields_and_values(fields, old_values_for_fields(fields))
end