Sha256: 56b04eb7fd20219016f556e183056babef5255dd6bdbac50de19e3da2318a8db

Contents?: true

Size: 744 Bytes

Versions: 9

Compression:

Stored size: 744 Bytes

Contents

# frozen_string_literal: true

module SecondLevelCache
  module ActiveRecord
    module Associations
      module BelongsToAssociation
        def find_target
          return super unless klass.second_level_cache_enabled?
          cache_record = klass.read_second_level_cache(second_level_cache_key)
          if cache_record
            return cache_record.tap { |record| set_inverse_instance(record) }
          end

          record = super
          return nil unless record

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

        private

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
second_level_cache-2.6.0 lib/second_level_cache/active_record/belongs_to_association.rb
second_level_cache-2.5.3 lib/second_level_cache/active_record/belongs_to_association.rb
second_level_cache-2.5.2 lib/second_level_cache/active_record/belongs_to_association.rb
second_level_cache-2.5.0 lib/second_level_cache/active_record/belongs_to_association.rb
second_level_cache-2.4.4 lib/second_level_cache/active_record/belongs_to_association.rb
second_level_cache-2.4.3 lib/second_level_cache/active_record/belongs_to_association.rb
second_level_cache-2.4.2 lib/second_level_cache/active_record/belongs_to_association.rb
second_level_cache-2.4.1 lib/second_level_cache/active_record/belongs_to_association.rb
second_level_cache-2.4.0 lib/second_level_cache/active_record/belongs_to_association.rb