Module: IdentityCache::CacheKeyGeneration

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

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

DEFAULT_NAMESPACE =
"IDC:#{CACHE_VERSION}:"

Class Method Summary collapse

Class Method Details

.denormalized_schema_hash(klass) ⇒ Object



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

def self.denormalized_schema_hash(klass)
  schema_string = denormalized_schema_string(klass)
  IdentityCache.memcache_hash(schema_string)
end

.denormalized_schema_string(klass) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/identity_cache/cache_key_generation.rb', line 11

def self.denormalized_schema_string(klass)
  schema_to_string(klass.columns).tap do |schema_string|
    klass.send(:all_cached_associations).sort.each do |name, association|
      klass.send(:check_association_scope, name)
      association.validate if association.embedded?
      case association
      when Cached::Recursive::Association
        schema_string << ",#{name}:(#{denormalized_schema_hash(association.reflection.klass)})"
      when Cached::Reference::HasMany
        schema_string << ",#{name}:ids"
      when Cached::Reference::HasOne
        schema_string << ",#{name}:id"
      end
    end
  end
end

.schema_to_string(columns) ⇒ Object



7
8
9
# File 'lib/identity_cache/cache_key_generation.rb', line 7

def self.schema_to_string(columns)
  columns.sort_by(&:name).map { |c| "#{c.name}:#{c.type}" }.join(',')
end