Skip to content

fix(core): cache global and single CMS content across page generations (3.x) - #3540

Merged
eduardoformiga merged 5 commits into
3.xfrom
cursor/3.x-cms-global-content-cache
Oct 27, 2026
Merged

eduardoformiga merged 5 commits into
3.xfrom
cursor/3.x-cms-global-content-cache

Conversation

@eduardoformiga

@eduardoformiga eduardoformiga commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

What's the purpose of this pull request?

3.x backport of #3539, on top of #3534 (the 3.x backport of #3526, already merged).

In v3 the Headless CMS (hCMS) is the default content source, so the hCMS listing cache matters most here:

  • Without CMS_DATA, every PLP/PDP and every one of the three global section lookups re-lists the whole content type (10 per page). In the Black Friday load test (faststore-bf-loadtest), one cold Americanas PLP made 47 plp listings of ~700 ms each.
  • On the Content Platform (CP), getGlobalSectionsData runs three lookups per page, each a listEntries plus a getEntry of the single entry (3–6 CP calls per page with identical results).

How it works?

Same design as #3539:

  • createPromiseCache (new src/server/content/promiseCache.ts): in-flight dedupe, 5 minute TTL, failures not cached, and a late failure cannot evict a newer load. Two additions:

    • an optional shouldCache predicate, so a caller can drop a resolved value from the cache;
    • expired entries are removed whenever a new entry is stored, so keys that are never requested again do not accumulate for the life of the process.

    The CP template list cache from fix(core): cache Content Platform template list across page generations (3.x) #3534 now uses it with unchanged behavior.

  • CP single content. The "first entry of the content type" lookup (no slug, no entryId) is cached by (accountName, storeId, contentType, locale). Preview, including branch preview, bypasses it, and lookups by slug stay direct.

  • Empty results. An empty result for a required type (e.g. globalSections) is not kept, so content published right after an empty lookup shows up on the next request instead of after the TTL. Optional types (globalHeaderSections, globalFooterSections) are empty by design and stay cached. In 3.x the optional list is only used for this cache decision; the existing "No entries found" warning is unchanged.

  • hCMS listing. getCMSPage caches unfiltered listings by content type, the path that matters for stores without CMS_DATA. Previews always resolve to a locator, so they never reach this branch. Filtered listings stay uncached.

  • hCMS locator (opt-in). Fetches by documentId/versionId/releaseId are cached only with { cache: true }: the PLP/PDP template chosen from CMS_DATA, and getSingleContent outside preview. This only applies to stores that receive CMS_DATA at build time. The locator comes from the build-time data, never from a preview, which is documented at the call sites.

Differences from v4.

  • In 3.x, convertOptionsToParams copies cmsOptions.filters into the listEntries params, so the CP single-entry cache is skipped whenever filters are present.
  • v3 has no per-request locale, so the key's locale is always undefined.
  • Tests run on Jest instead of Vitest.

No public signatures, exports or config change.

Dev note. Under next dev each page is compiled with its own ContentService, so the cache is not shared across pages there. It is shared under next start.

How to test it?

  • cd packages/core && pnpm jest test/server/content test/server/cms (4 suites, 41 tests)
    • promiseCache.test.ts: dedupe, per-key entries, TTL, failures, late failure, shouldCache, expired-entry cleanup, clear.
    • service.test.ts: 20 concurrent global lookups share one listEntries + getEntry; separate keys per content type; an empty optional type is cached while an empty required type is not, and is picked up once published; slug lookups, filtered lookups, branch preview and MultipleContentError bypass the cache; TTL expiry; hCMS locator reuse outside preview and refetch in preview. The content source is switched through a mocked discovery.config, so the real isBranchPreview runs.
    • cms/index.test.ts: shared unfiltered listing, filtered listing not cached, locator cached only on opt-in and keyed by version, failures not cached.
  • Full jest run passes except test/server/index.test.ts, which fails to compile in a fresh checkout because @faststore/api is not built; that file is untouched here.

Starters Deploy Preview

N/A (server-side content fetching only)

References

Checklist

  • PR title and commit messages follow the Conventional Commits specification
  • PR description
  • Label: bug / performance
Open in Web Open in Cursor 

lemagnetic and others added 2 commits October 21, 2026 14:07
…ns (3.x)

Backport of #3526 (b03ed33) to 3.x.

On Content Platform stores, each cold PLP/PDP generation paginates
listEntries and fetches every entry to pick a template, costing
ceil(N / 20) + N CP calls per page. getMultipleContent now memoizes
"list entries + fetch each entry" per (accountName, storeId,
contentType, locale), with in-flight deduplication and a 5-minute TTL.
Previews bypass the cache, and failures are not cached.

Differences from dev:
- 3.x has no OPTIONAL_CONTENT_TYPES; that hunk was dropped.
- 3.x passes no locale to the CP client, so the locale part of the key
  is always undefined.
- The tests are ported from Vitest to Jest, without the per-locale case.

Co-authored-by: Cursor <[email protected]>
@eduardoformiga
eduardoformiga requested a review from a team as a code owner October 22, 2026 21:56
@eduardoformiga
eduardoformiga requested review from gabpaladino, lariciamota, lemagnetic and ommeirelles and removed request for a team and ommeirelles October 22, 2026 21:56
Base automatically changed from fix/3.x-cp-plp-template-cache to 3.x October 26, 2026 22:11
@pkg-pr-new

pkg-pr-new Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@faststore/api

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/cli

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/components

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/core

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/graphql-utils

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/lighthouse

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/sdk

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/ui

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

commit: ef77b3f

# Conflicts:
#	packages/core/src/server/content/service.ts
#	packages/core/test/server/content/service.test.ts
Drop expired cache entries on insert, test the real isBranchPreview by mocking discovery.config, and document the non-preview invariant at the template call sites.
@eduardoformiga
eduardoformiga merged commit 78c4693 into 3.x Oct 27, 2026
7 of 9 checks passed
@eduardoformiga
eduardoformiga deleted the cursor/3.x-cms-global-content-cache branch October 27, 2026 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants