fix: add cacheLife("max") to build-time cached functions and clarify throw-vs-catch caching rule

- Add `cacheLife("max")` to `getLocalImage` (OG image) and `getStaticRoutes` (sitemap) so entries are held as long as possible during prerender instead of expiring at the default TTL
- Update AGENTS.md to distinguish build-time reads (catch inside the cached function, return a fallback, use a short `cacheLife` on the error path) from request-time reads (may throw from the cached function since they never run during prerender)
- Expand the `getCachedComments` comment to explain why throwing is only safe there: a throw inside `"use cache"` during prerender fails the build even if the caller catches it
This commit is contained in:
jake committed 2026-10-03 09:55:33 -04:00
1 parent d3b2d07de7
commit 3baffbbd29
4 files changed
+7 -2

No files matched your search

+2 -1
View File
@@ -17,7 +17,8 @@ export const commentsTag = (pageSlug: string) => `comments-${pageSlug}`;
/**
* Shared across server instances since it's read at request time (inside dynamic holes), not at prerender. Throws on
* failure so an error is never cached.
* failure so an error is never cached -- only safe because it never runs during prerender, where a throw inside
* "use cache" fails the build even if caught.
*/
const getCachedComments = async (pageSlug: string): Promise<CommentWithUser[]> => {
"use cache: remote";