Skip to content

fix(caching): invalidate list caches on entity update events - #15747

Merged
kodiakhq[bot] merged 1 commit into
medusajs:developfrom
imharjot:fix/caching-invalidate-list-on-update
Jun 19, 2026
Merged

kodiakhq[bot] merged 1 commit into
medusajs:developfrom
imharjot:fix/caching-invalidate-list-on-update

Conversation

@imharjot

Copy link
Copy Markdown
Contributor

What

buildAffectedCacheKeys in @medusajs/caching now also emits the ${EntityType}:list:* invalidation tag for updated operations, not just created/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:

  1. Create a draft product.
  2. GET /store/products — cached; the draft is excluded by the status filter, so it's not in the cached array.
  3. Publish it (admin API) — fires product.updated.
  4. GET /store/products — stale; the product is missing until TTL expires.

On updated, only Product:<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 is updated) to include the :list:* tag.

cd packages/modules/caching && yarn test

All unit tests pass locally.

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.
@imharjot
imharjot requested a review from a team as a code owner June 17, 2026 21:23
@changeset-bot

changeset-bot Bot commented Jun 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f98e628

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 79 packages
Name Type
@medusajs/caching Patch
@medusajs/medusa Patch
@medusajs/test-utils Patch
@medusajs/medusa-oas-cli Patch
integration-tests-http Patch
@medusajs/analytics Patch
@medusajs/api-key Patch
@medusajs/auth Patch
@medusajs/cart Patch
@medusajs/currency Patch
@medusajs/customer Patch
@medusajs/file Patch
@medusajs/fulfillment Patch
@medusajs/index Patch
@medusajs/inventory Patch
@medusajs/link-modules Patch
@medusajs/locking Patch
@medusajs/notification Patch
@medusajs/order Patch
@medusajs/payment Patch
@medusajs/pricing Patch
@medusajs/product Patch
@medusajs/promotion Patch
@medusajs/rbac Patch
@medusajs/region Patch
@medusajs/sales-channel Patch
@medusajs/settings Patch
@medusajs/stock-location Patch
@medusajs/store Patch
@medusajs/tax Patch
@medusajs/translation Patch
@medusajs/user Patch
@medusajs/workflow-engine-inmemory Patch
@medusajs/workflow-engine-redis Patch
@medusajs/draft-order Patch
@medusajs/loyalty-plugin Patch
@medusajs/oas-github-ci Patch
@medusajs/cache-inmemory Patch
@medusajs/cache-redis Patch
@medusajs/event-bus-local Patch
@medusajs/event-bus-redis Patch
@medusajs/analytics-local Patch
@medusajs/analytics-posthog Patch
@medusajs/auth-emailpass Patch
@medusajs/auth-github Patch
@medusajs/auth-google Patch
@medusajs/caching-redis Patch
@medusajs/file-local Patch
@medusajs/file-s3 Patch
@medusajs/fulfillment-manual Patch
@medusajs/locking-postgres Patch
@medusajs/locking-redis Patch
@medusajs/notification-local Patch
@medusajs/notification-sendgrid Patch
@medusajs/payment-stripe Patch
@medusajs/core-flows Patch
@medusajs/framework Patch
@medusajs/js-sdk Patch
@medusajs/modules-sdk Patch
@medusajs/orchestration Patch
@medusajs/types Patch
@medusajs/utils Patch
@medusajs/workflows-sdk Patch
@medusajs/http-types-generator Patch
@medusajs/cli Patch
@medusajs/deps Patch
@medusajs/eslint-plugin Patch
@medusajs/telemetry Patch
@medusajs/admin-bundler Patch
@medusajs/admin-sdk Patch
@medusajs/admin-shared Patch
@medusajs/admin-vite-plugin Patch
@medusajs/dashboard Patch
@medusajs/icons Patch
@medusajs/toolbox Patch
@medusajs/ui-preset Patch
create-medusa-app Patch
medusa-dev-cli Patch
@medusajs/ui Patch

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

@medusa-os-bot

medusa-os-bot Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

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

@shahednasser shahednasser left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Stale cache served for list responses with caching feature flag enabled

2 participants