Module: IdentityCache::CacheKeyGeneration
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/identity_cache/cache_key_generation.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- DEFAULT_NAMESPACE =
"IDC:#{CACHE_VERSION}:".freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#attribute_cache_key_for_attribute_and_current_values(attribute, fields) ⇒ Object
:nodoc:.
-
#attribute_cache_key_for_attribute_and_previous_values(attribute, fields) ⇒ Object
:nodoc:.
-
#current_values_for_fields(fields) ⇒ Object
:nodoc:.
-
#old_values_for_fields(fields) ⇒ Object
:nodoc:.
-
#primary_cache_index_key ⇒ Object
:nodoc:.
-
#secondary_cache_index_key_for_current_values(fields) ⇒ Object
:nodoc:.
-
#secondary_cache_index_key_for_previous_values(fields) ⇒ Object
:nodoc:.
Class Method Details
.denormalized_schema_hash(klass) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/identity_cache/cache_key_generation.rb', line 10 def self.denormalized_schema_hash(klass) schema_string = schema_to_string(klass.columns) if klass.include?(IdentityCache) klass.send(:all_cached_associations).sort.each do |name, | case [:embed] when true schema_string << ",#{name}:(#{denormalized_schema_hash([:association_class])})" when :ids schema_string << ",#{name}:ids" end end end IdentityCache.memcache_hash(schema_string) end |
.schema_to_string(columns) ⇒ Object
6 7 8 |
# File 'lib/identity_cache/cache_key_generation.rb', line 6 def self.schema_to_string(columns) columns.sort_by(&:name).map{|c| "#{c.name}:#{c.type}"}.join(',') end |
Instance Method Details
#attribute_cache_key_for_attribute_and_current_values(attribute, fields) ⇒ Object
:nodoc:
69 70 71 |
# File 'lib/identity_cache/cache_key_generation.rb', line 69 def attribute_cache_key_for_attribute_and_current_values(attribute, fields) # :nodoc: self.class.rails_cache_key_for_attribute_and_fields_and_values(attribute, fields, current_values_for_fields(fields)) end |
#attribute_cache_key_for_attribute_and_previous_values(attribute, fields) ⇒ Object
:nodoc:
73 74 75 |
# File 'lib/identity_cache/cache_key_generation.rb', line 73 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 |
#current_values_for_fields(fields) ⇒ Object
:nodoc:
77 78 79 |
# File 'lib/identity_cache/cache_key_generation.rb', line 77 def current_values_for_fields(fields) # :nodoc: fields.collect {|field| self.send(field)} end |
#old_values_for_fields(fields) ⇒ Object
:nodoc:
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/identity_cache/cache_key_generation.rb', line 81 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_key ⇒ Object
:nodoc:
57 58 59 |
# File 'lib/identity_cache/cache_key_generation.rb', line 57 def primary_cache_index_key # :nodoc: self.class.rails_cache_key(id) end |
#secondary_cache_index_key_for_current_values(fields) ⇒ Object
:nodoc:
61 62 63 |
# File 'lib/identity_cache/cache_key_generation.rb', line 61 def secondary_cache_index_key_for_current_values(fields) # :nodoc: self.class.rails_cache_index_key_for_fields_and_values(fields, current_values_for_fields(fields)) end |
#secondary_cache_index_key_for_previous_values(fields) ⇒ Object
:nodoc:
65 66 67 |
# File 'lib/identity_cache/cache_key_generation.rb', line 65 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 |