Repository navigation
fix(core): cache global and single CMS content across page generations (3.x) - #3540
Merged
Merged
Conversation
…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
requested review from
gabpaladino,
lariciamota,
lemagnetic and
ommeirelles
and removed request for
a team and
ommeirelles
October 22, 2026 21:56
2 of 3 tasks
@faststore/api
@faststore/cli
@faststore/components
@faststore/core
@faststore/graphql-utils
@faststore/lighthouse
@faststore/sdk
@faststore/ui
commit: |
# 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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 47plplistings of ~700 ms each.getGlobalSectionsDataruns three lookups per page, each alistEntriesplus agetEntryof the single entry (3–6 CP calls per page with identical results).How it works?
Same design as #3539:
createPromiseCache(newsrc/server/content/promiseCache.ts): in-flight dedupe, 5 minute TTL, failures not cached, and a late failure cannot evict a newer load. Two additions:shouldCachepredicate, so a caller can drop a resolved value from the cache;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.
getCMSPagecaches unfiltered listings by content type, the path that matters for stores withoutCMS_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/releaseIdare cached only with{ cache: true }: the PLP/PDP template chosen fromCMS_DATA, andgetSingleContentoutside preview. This only applies to stores that receiveCMS_DATAat build time. The locator comes from the build-time data, never from a preview, which is documented at the call sites.Differences from v4.
convertOptionsToParamscopiescmsOptions.filtersinto thelistEntriesparams, so the CP single-entry cache is skipped whenever filters are present.undefined.No public signatures, exports or config change.
Dev note. Under
next deveach page is compiled with its ownContentService, so the cache is not shared across pages there. It is shared undernext 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 onelistEntries+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 andMultipleContentErrorbypass the cache; TTL expiry; hCMS locator reuse outside preview and refetch in preview. The content source is switched through a mockeddiscovery.config, so the realisBranchPreviewruns.cms/index.test.ts: shared unfiltered listing, filtered listing not cached, locator cached only on opt-in and keyed by version, failures not cached.jestrun passes excepttest/server/index.test.ts, which fails to compile in a fresh checkout because@faststore/apiis not built; that file is untouched here.Starters Deploy Preview
N/A (server-side content fetching only)
References
Checklist
bug/performance