docs: clarify cacheLife() cannot be called at module scope#92326
Merged
Conversation
Made-with: Cursor
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the cacheLife API reference documentation to explicitly state that cacheLife() must be called inside a function body (not at module scope), and that calling it at the top level will throw an error, even if 'use cache' is declared at file scope.
Changes:
- Strengthened the “Good to know” guidance from “should be placed within the function” to “must be called inside a function body.”
- Documented that module-scope usage throws an error and clarified the relationship to file-level
'use cache'.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Made-with: Cursor
icyJoseph
reviewed
Apr 7, 2026
icyJoseph
reviewed
Apr 7, 2026
icyJoseph
reviewed
Apr 7, 2026
Co-authored-by: Joseph <joseph.chamochumbi@vercel.com>
icyJoseph
approved these changes
Apr 8, 2026
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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?
Update the "Good to know" callout in the
cacheLifedocs to explicitly state thatcacheLife()must be called inside a function body, not at module scope, and that doing so throws an error.Why?
Calling
cacheLife('days')at module scope in a file with'use cache'at the top throws:`cacheLife()` can only be called inside a "use cache" function. This is technically correct (module scope is not inside a function), but the previous docs only saidcacheLife"should be placed within the function" without mentioning it errors. Both developers and AI agents hit this when they placecacheLife()next to the file-level'use cache'directive at the top of the module.How?
Replaced the soft "should be placed within the function" language with explicit "must be called inside a function body, not at module scope" and noted that it throws an error otherwise.
PR checklist (Improving Documentation)
pnpm prettier-fixto fix formatting issues before opening the PRMade with Cursor