Both work. The right pick depends on how often the feed changes and how many regions you serve. A quick comparison:
| Strategy | Best for | Trade-off |
|---|---|---|
| Edge cache | Many regions, read-heavy | Stale for up to the TTL |
| In-memory | One region, low traffic | Cold on every deploy |
| Both | Mixed traffic | Two places to invalidate |
type Feed = { items: { id: string; title: string }[]; updatedAt: number };export async function readFeed(load: () => Promise<Feed>, ttl = 60_000) { const cached = cache.get("feed"); if (cached && Date.now() - cached.updatedAt < ttl) return cached; const fresh = await load(); cache.set("feed", fresh); return fresh;}Things to check before shipping:
stale-while-revalidate window so readers never wait on a refresh.A cache you cannot purge is a bug waiting for a deadline.
More background lives in the sample caching guide.
Use readFeed() with a short TTL, then tune it. Avoid global shared keys.