Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Patch `run_callbacks` instead of `_run_commit_callbacks` to expire cache prior to `after_commit` callbacks. (#602)

## 1.6.3

- Split the `with_deferred_parent_expiration` and `with_deferred_parent_expiration`. (#578)
Expand Down
17 changes: 13 additions & 4 deletions lib/identity_cache/query_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,20 @@ def cache_fetch_includes
# cache reads that happen from the ordering of callbacks. For example, if an after_commit
# callback enqueues a background job, then we don't want it to be possible for the
# background job to run and load data from the cache before it is invalidated.
def _run_commit_callbacks
if destroyed? || transaction_changed_attributes.present?
expire_cache
if ActiveRecord.version >= Gem::Version.new("7.1")
def run_callbacks(kind, type = nil)
if kind == :commit && (destroyed? || transaction_changed_attributes.present?)
expire_cache
end
super
end
else
def run_callbacks(kind)
if kind == :commit && (destroyed? || transaction_changed_attributes.present?)
expire_cache
end
super
end
super
end

# Invalidate the cache data associated with the record. Returns `true` on success,
Expand Down
Loading