feat(cache): support custom configured cacheLife profiles - #3307
Open
NriotHrreion wants to merge 5 commits into
Open
NriotHrreion wants to merge 5 commits into
NriotHrreion wants to merge 5 commits into
Conversation
@vinext/cloudflare
create-vinext-app
@vinext/types
vinext
@cloudflare/workers-response-store
commit: |
Contributor
Performance benchmarksCompared 1 improved · 1 regressed · 4 within ±1.5%
View detailed results and traces 🟢 improvement · 🔴 regression · ⚫ change below 1.5% · paired base/head |
Member
|
/bigbonk review for issues |
Contributor
|
@james-elicx Bonk workflow was cancelled. View workflow run · To retry, trigger Bonk again. |
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.
Overview
vinext previously ignored
cacheLifeprofiles configured innext.config.*or inlinevinext({ nextConfig }). As a result, calls such ascacheLife("blog")warned about an unknown profile, and configured overrides of built-in or default profiles had no effect.This PR enables configured profiles across
cacheLife(),unstable_cacheLife(), default caching andrevalidateTag(tag, profile), with consistent lifetime settings in development, Node production and Cloudflare Workers production. Applications can define custom profiles, override built-in and default profiles, and let partial profiles inherit missing values fromdefault. Existing built-in settings are preserved when no profiles are configured.For example, an application can configure its profiles in
next.config.ts:All durations are in seconds. Calling
cacheLife("blog")applies the custom profile. CallingcacheLife("hours")uses the overridden expiration and inheritsstale: 300andrevalidate: 900fromdefault. Cached functions without an explicitcacheLife()call use the configureddefaultprofile.What changed
default,seconds,minutesand etc., is extracted frompackages/vinext/src/shims/cache-request-state.tsintopackages/vinext/src/utils/cache-life-profiles.ts.cacheLife?: Record<string, CacheLifeConfig>andexperimental.cacheLife?: Record<string, CacheLifeConfig>(for compatibility) intoNextConfigtype. vinext readsconfig.cacheLifefirst, if not defined, then fallback toconfig.experimental.cacheLifeand print a deprecation warning.cacheLifeconfiguration viavite.config.ts.cacheLife(), pass the resolvedcacheLifeProfilesinto_setRequestScopedCacheLife():cacheLifefields fromdefaultafter merging explicit durations, and preserve and replay lifetime metadata on private cache hits.Testing
pnpm test tests/cache-life-profiles.test.ts tests/cache-life-runtime.test.ts tests/cache-life-config.test.ts tests/cache-life-build.test.tspnpm test tests/next-config.test.ts tests/pages-router.test.ts tests/prerender-config.test.tsNotes
This PR only supports configured runtime profiles. Typegen of
cache-life.d.tsis not implemented.Refs #3244