Repository navigation
fix(caching): invalidate list caches on entity update events - #15747
kodiakhq[bot] merged 1 commit into
Conversation
Closes medusajs#14903. Add "updated" to the operation gate in buildAffectedCacheKeys so updates also emit the `<Type>:list:*` tag. Without it, publishing a previously-filtered entity (e.g. draft -> published product) leaves stale list responses cached until TTL, since no cache entry was tagged with the entity id.
🦋 Changeset detectedLatest commit: f98e628 The changes in this PR will be included in the next version bump. This PR includes changesets to release 79 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Thanks for the contribution! Initial automated review looks good. Clean, well-scoped fix for the linked stale-list-cache bug (#14903, good first issue). Adds the 'updated' operation to the list-invalidation gate in buildAffectedCacheKeys so list caches are busted when an update can change filter matching (e.g. draft->published). Entity-level tag unchanged. Template complete (What/Why/How/Testing), changeset present, unit tests updated to pin the new behavior. No security or correctness concerns; the more aggressive list invalidation is the intended trade-off. Triggered by: new PR opened |
What
buildAffectedCacheKeysin@medusajs/cachingnow also emits the${EntityType}:list:*invalidation tag forupdatedoperations, not justcreated/deleted.Why
Closes #14903. With
featureFlags: { caching: true }, list endpoints (e.g.GET /store/products) keep serving stale data after an update that changes whether an entity matches a filter:GET /store/products— cached; the draft is excluded by the status filter, so it's not in the cached array.product.updated.GET /store/products— stale; the product is missing until TTL expires.On
updated, onlyProduct:<id>was generated. Since the draft was filtered out of the cached list, nothing was tagged with that id, so the stale list survived. The:list:*wildcard tag (which is applied to cached list responses) was never produced for updates of entities that weren't already part of a cached array. The cache layer can't know which fields are filter-relevant, so list caches have to be busted on update.How
packages/modules/caching/src/utils/parser.ts: add"updated"to the existing operation gate. Kept the gate intact rather than dropping it for all operations, per the discussion on the earlier attempt (#15337) — this keeps invalidation predictable. The entity-level tag (Product:<id>) is unchanged.Testing
Unit tests in
parser.test.ts: flipped the assertion that pinned the old behavior into a regression test for the updated operation, and updated the default-operation expectations (the default op isupdated) to include the:list:*tag.All unit tests pass locally.