Docs · Configure
Next.js caching on homeport
A Next.js app on homeport caches the way Next does when you run it yourself. Time-based caching works with nothing to set up. On-demand revalidation (revalidateTag, revalidatePath, updateTag) needs a cache that every copy of your app shares, such as Redis.
What works with nothing to set up
- Time-based ISR. A page with
export const revalidate = 60is rendered again at most once a minute, by each copy of the app. 'use cache'with a lifetime. A function or component withcacheLife('hours')or anothercacheLifeprofile is kept for that long, then computed again.
Each copy of your app keeps its own cache in memory and on its own disk. Two copies may each compute the same page, but neither serves anything older than the lifetime you set. That is the whole promise of time-based caching, so it holds without a shared cache.
On-demand revalidation needs a shared cache
revalidateTag, revalidatePath and updateTag only reach the copy of your app that ran them. Next keeps the list of revalidated tags in that process’s memory. Next’s own docs say so: “revalidation events are local by default”.
That breaks in two ways on homeport, even if you only ever run one copy:
- More copies. When homeport adds copies under load, the other copies never hear about the revalidation and keep serving the old page.
- A fresh process. An app that starts fresh after a long sleep, restarts after a crash, gets a new copy when it scales up, or moves starts with an empty list. It goes back to the page from your build, or whatever its disk last had, as if nothing was ever revalidated. A page with a
revalidatetime catches up when that time runs out. A page that is only revalidated on demand has no time limit, so it stays old until the next deploy.
A wake within a day keeps the process and its list, but a fresh start comes sooner or later (see Sleeping, scaling and sizes), so the second case happens to every app. If your app calls revalidateTag, revalidatePath or updateTag, add a shared cache.
Adding a shared cache
Next has two cache settings, and an app that revalidates on demand needs both pointed at the shared store:
| Setting | What it caches |
|---|---|
cacheHandler | Pages (ISR), route handlers and cached fetch |
cacheHandlers | 'use cache' functions and components |
Both packages below keep the revalidated tags in Redis, so every copy and every fresh process sees them. Set REDIS_URL as a variable on the environment (see Environments and variables).
On Node.js
@mrjasonroy/cache-components-cache-handler sets both for you. Install the release that matches your Next.js minor, pinned:
npm install --save-exact @mrjasonroy/[email protected]import { withCache } from '@mrjasonroy/cache-components-cache-handler'
export default withCache({ cacheComponents: true })Without REDIS_URL it keeps everything in memory, so local development needs nothing. With it, pages and revalidations are shared, and if Redis goes down the app keeps serving from memory.
On Bun
next-bun-cache-handler uses Bun’s built-in Redis client, and needs your app to run on Bun. Its README lists the Next.js versions it is tested with. It has one handler for each setting:
import { createCacheHandler } from 'next-bun-cache-handler'
export default createCacheHandler({ type: 'redis' })import { createBunIncrementalCacheHandler } from 'next-bun-cache-handler'
export default createBunIncrementalCacheHandler()const nextConfig = {
cacheComponents: true,
cacheHandlers: {
default: require.resolve('./cache-handler.ts'),
remote: require.resolve('./cache-handler.ts'),
},
cacheHandler: require.resolve('./cache-handler-pages.ts'),
cacheMaxMemorySize: 0,
}
export default nextConfigcacheMaxMemorySize: 0 turns off the memory cache Next keeps in front of cacheHandler, so every copy reads pages from Redis.
Postgres
Your app may already have a Postgres database in its region, which would make a good shared cache. We don’t know of a maintained Postgres cache handler for Next.js 16 yet. Next’s cacheHandlers docs describe the interface if you want to write your own. Use DATABASE_URL_UNPOOLED for anything that holds a session, such as LISTEN.
What a Redis cache costs
Any Redis works. With Upstash, for example (prices from their pricing page on 6 November 2026):
- Free: 500,000 commands and 250 MB a month, one database.
- Pay as you go: $0.20 per 100,000 commands, with the first GB of storage free.
- Fixed: from $10 a month for 250 MB, with no charge per command.
A page served from the shared cache takes about 4 Redis commands: reading the page, checking its tags, and reading a couple of 'use cache' entries. At a million page views a month that is about 4 million commands: $8 a month on pay as you go, or the $10 fixed plan. Pick the Upstash region nearest your app: each command is a round trip, so a far region adds to every uncached page.