Skip to content

Commit

Permalink
Namespace Thread.current keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Stivaros committed Jun 14, 2024
1 parent fddbf83 commit 1aba576
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions lib/identity_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,20 +194,20 @@ def fetch_multi(*keys)
end

def with_deferred_parent_expiration
raise NestedDeferredParentBlockError if Thread.current[:deferred_parent_expiration]
raise NestedDeferredParentBlockError if Thread.current[:idc_deferred_parent_expiration]

Thread.current[:deferred_parent_expiration] = true
Thread.current[:parent_records_for_cache_expiry] = Set.new
Thread.current[:idc_deferred_parent_expiration] = true
Thread.current[:idc_parent_records_for_cache_expiry] = Set.new

result = yield

Thread.current[:deferred_parent_expiration] = nil
Thread.current[:parent_records_for_cache_expiry].each(&:expire_primary_index)
Thread.current[:idc_deferred_parent_expiration] = nil
Thread.current[:idc_parent_records_for_cache_expiry].each(&:expire_primary_index)

result
ensure
Thread.current[:deferred_parent_expiration] = nil
Thread.current[:parent_records_for_cache_expiry].clear
Thread.current[:idc_deferred_parent_expiration] = nil
Thread.current[:idc_parent_records_for_cache_expiry].clear
end

def with_fetch_read_only_records(value = true)
Expand Down
4 changes: 2 additions & 2 deletions lib/identity_cache/parent_model_expiration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def expire_parent_caches
add_parents_to_cache_expiry_set(parents_to_expire)
parents_to_expire.select! { |parent| parent.class.primary_cache_index_enabled }
parents_to_expire.reduce(true) do |all_expired, parent|
if Thread.current[:deferred_parent_expiration]
Thread.current[:parent_records_for_cache_expiry] << parent
if Thread.current[:idc_deferred_parent_expiration]
Thread.current[:idc_parent_records_for_cache_expiry] << parent
next parent
end
parent.expire_primary_index && all_expired
Expand Down

0 comments on commit 1aba576

Please sign in to comment.