Sha256: 14b103579d9deb01c175f3effca92db4a98b74793804d347251432a2a328a486

Contents?: true

Size: 949 Bytes

Versions: 23

Compression:

Stored size: 949 Bytes

Contents

# -*- encoding : utf-8 -*-
module SecondLevelCache
  module ActiveRecord
    module Associations
      module BelongsToAssociation
        extend ActiveSupport::Concern
        included do
          class_eval do
            alias_method_chain :find_target, :second_level_cache
          end
        end

        def find_target_with_second_level_cache
          return find_target_without_second_level_cache unless klass.second_level_cache_enabled?
          cache_record = klass.read_second_level_cache(second_level_cache_key)
          return cache_record.tap{|record| set_inverse_instance(record)} if cache_record
          record = find_target_without_second_level_cache

          record.tap do |r|
            set_inverse_instance(r)
            r.write_second_level_cache
          end if record
        end

        private

        def second_level_cache_key
          owner[reflection.foreign_key]
        end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
second_level_cache-2.1.16 lib/second_level_cache/active_record/belongs_to_association.rb
second_level_cache-2.1.15 lib/second_level_cache/active_record/belongs_to_association.rb
second_level_cache-2.1.14 lib/second_level_cache/active_record/belongs_to_association.rb
second_level_cache-2.1.13 lib/second_level_cache/active_record/belongs_to_association.rb
second_level_cache-2.1.10 lib/second_level_cache/active_record/belongs_to_association.rb
second_level_cache-2.1.9 lib/second_level_cache/active_record/belongs_to_association.rb
second_level_cache-2.1.8 lib/second_level_cache/active_record/belongs_to_association.rb
second_level_cache-2.1.7 lib/second_level_cache/active_record/belongs_to_association.rb
second_level_cache-2.1.6 lib/second_level_cache/active_record/belongs_to_association.rb
second_level_cache-2.1.5 lib/second_level_cache/active_record/belongs_to_association.rb
second_level_cache-2.1.2 lib/second_level_cache/active_record/belongs_to_association.rb
second_level_cache-2.1.1 lib/second_level_cache/active_record/belongs_to_association.rb
second_level_cache-2.1.0 lib/second_level_cache/active_record/belongs_to_association.rb
second_level_cache-2.1.0.rc2 lib/second_level_cache/active_record/belongs_to_association.rb
second_level_cache-2.1.0.rc1 lib/second_level_cache/active_record/belongs_to_association.rb
second_level_cache-2.0.0 lib/second_level_cache/active_record/belongs_to_association.rb
second_level_cache-2.0.0.rc1 lib/second_level_cache/active_record/belongs_to_association.rb
second_level_cache-2.0.0.beta lib/second_level_cache/active_record/belongs_to_association.rb
second_level_cache-1.6.2 lib/second_level_cache/active_record/belongs_to_association.rb
second_level_cache-1.6.1 lib/second_level_cache/active_record/belongs_to_association.rb