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



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

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

.denormalized_schema_string(klass) ⇒ Object



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

def denormalized_schema_string(klass)
  schema_to_string(klass.columns).tap do |schema_string|
    klass.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



9
10
11
# File 'lib/identity_cache/cache_key_generation.rb', line 9

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