Skip to content

Commit

Permalink
Automatically install parent expiration hooks in parent_expiration_en…
Browse files Browse the repository at this point in the history
…tries
  • Loading branch information
dylanahsmith committed Jun 15, 2021
1 parent c5038e5 commit 4f7e0da
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/identity_cache/parent_model_expiration.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true
module IdentityCache
module ParentModelExpiration # :nodoc:
# @api private
module ParentModelExpiration
extend ActiveSupport::Concern
include ArTransactionChanges

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 4f7e0da

Please sign in to comment.