From 4f7e0da0b310385bb48cc745aeaed5df55efcdc8 Mon Sep 17 00:00:00 2001 From: Dylan Thacker-Smith Date: Tue, 15 Jun 2021 17:36:51 -0400 Subject: [PATCH] Automatically install parent expiration hooks in parent_expiration_entries --- lib/identity_cache/parent_model_expiration.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/identity_cache/parent_model_expiration.rb b/lib/identity_cache/parent_model_expiration.rb index 25fbb956..fcd9e0e0 100644 --- a/lib/identity_cache/parent_model_expiration.rb +++ b/lib/identity_cache/parent_model_expiration.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true module IdentityCache - module ParentModelExpiration # :nodoc: + # @api private + module ParentModelExpiration extend ActiveSupport::Concern include ArTransactionChanges @@ -35,9 +36,16 @@ def lazy_hooks end end + module ClassMethods + def parent_expiration_entries + ParentModelExpiration.install_pending_parent_expiry_hooks(cached_model) + _parent_expiration_entries + end + end + included do - class_attribute(:parent_expiration_entries) - self.parent_expiration_entries = Hash.new { |hash, key| hash[key] = [] } + class_attribute(:_parent_expiration_entries) + self._parent_expiration_entries = Hash.new { |hash, key| hash[key] = [] } end def expire_parent_caches @@ -49,7 +57,6 @@ def expire_parent_caches end def add_parents_to_cache_expiry_set(parents_to_expire) - ParentModelExpiration.install_pending_parent_expiry_hooks(cached_model) self.class.parent_expiration_entries.each do |association_name, cached_associations| parents_to_expire_on_changes(parents_to_expire, association_name, cached_associations) end