mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2026-10-27 12:36:24 -04:00
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:
4 files changed
+7
-2
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
|
||||
import { cacheLife } from "next/cache";
|
||||
import { notFound } from "next/navigation";
|
||||
import { ImageResponse } from "next/og";
|
||||
|
||||
@@ -31,6 +32,7 @@ const loadGoogleFont = async (font: string, weight: number): Promise<ArrayBuffer
|
||||
|
||||
const getLocalImage = async (src: string): Promise<ArrayBuffer | string> => {
|
||||
"use cache";
|
||||
cacheLife("max");
|
||||
|
||||
// https://stackoverflow.com/questions/5775469/whats-the-valid-way-to-include-an-image-with-no-src/14115340#14115340
|
||||
const NO_IMAGE = "data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=";
|
||||
|
||||
Reference in new issue
Block a user