Sha256: 3cc49254be39c42009af2238943f6a64dbb9cfd030a2f027e0ffab9973e99935

Contents?: true

Size: 1.32 KB

Versions: 16

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

module IdentityCache
  module CacheKeyGeneration
    extend ActiveSupport::Concern
    DEFAULT_NAMESPACE = "IDC:#{CACHE_VERSION}:"

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

      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

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

    module ClassMethods
      def rails_cache_key_namespace
        ns = IdentityCache.cache_namespace
        ns.is_a?(Proc) ? ns.call(self) : ns
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
identity_cache-1.6.3 lib/identity_cache/cache_key_generation.rb
identity_cache-1.6.2 lib/identity_cache/cache_key_generation.rb
identity_cache-1.6.1 lib/identity_cache/cache_key_generation.rb
identity_cache-1.6.0 lib/identity_cache/cache_key_generation.rb
identity_cache-1.5.6 lib/identity_cache/cache_key_generation.rb
identity_cache-1.5.5 lib/identity_cache/cache_key_generation.rb
identity_cache-1.5.4 lib/identity_cache/cache_key_generation.rb
identity_cache-1.5.3 lib/identity_cache/cache_key_generation.rb
identity_cache-1.5.2 lib/identity_cache/cache_key_generation.rb
identity_cache-1.5.1 lib/identity_cache/cache_key_generation.rb
identity_cache-1.5.0 lib/identity_cache/cache_key_generation.rb
identity_cache-1.4.1 lib/identity_cache/cache_key_generation.rb
identity_cache-1.4.0 lib/identity_cache/cache_key_generation.rb
identity_cache-1.3.1 lib/identity_cache/cache_key_generation.rb
identity_cache-1.3.0 lib/identity_cache/cache_key_generation.rb
identity_cache-1.2.0 lib/identity_cache/cache_key_generation.rb