Problem with NextJs 14 cache in production
Unanswered
American black bear posted this in #help-forum
American black bearOP
Hi all, I'm experiencing inconsistent caching behavior in Next.js 14 between development and production environments.
Setup
- Next.js: 14 with App Router
- Build mode: Standalone
- CMS: Directus
- Cache strategy: Using tag-based caching on fetch calls and on-demand revalidation by Directus flow
In Development Mode cache works correctly - calls to Directus are only made when necessary.
In Production Mode, from Directus logs, I see API calls on every browser page refresh, despite cache should be active.
I also tried to use unstable_cache, works in DEV and not in PROD
Is this a known issue with Next.js 14 in standalone mode?
Does Next.js cache behave differently in production vs development?
Are there specific configurations needed to make cache work in standalone mode?
Thanks a tot!
Setup
- Next.js: 14 with App Router
- Build mode: Standalone
- CMS: Directus
- Cache strategy: Using tag-based caching on fetch calls and on-demand revalidation by Directus flow
In Development Mode cache works correctly - calls to Directus are only made when necessary.
In Production Mode, from Directus logs, I see API calls on every browser page refresh, despite cache should be active.
// Cache implementation example
const directus = createDirectus(process.env.NEXT_PUBLIC_API_URL || '').with(
rest({
onRequest: (options) => ({
...options,
next: {
revalidate: 3600,
tags: ['directus'],
},
}),
}),
);
I also tried to use unstable_cache, works in DEV and not in PROD
Is this a known issue with Next.js 14 in standalone mode?
Does Next.js cache behave differently in production vs development?
Are there specific configurations needed to make cache work in standalone mode?
Thanks a tot!
1 Reply
@American black bear Hi all, I'm experiencing inconsistent caching behavior in Next.js 14 between development and production environments.
**Setup**
- Next.js: 14 with App Router
- Build mode: Standalone
- CMS: Directus
- Cache strategy: Using tag-based caching on fetch calls and on-demand revalidation by Directus flow
In **Development Mode** cache works correctly - calls to Directus are only made when necessary.
In **Production Mode**, from Directus logs, I see API calls on every browser page refresh, despite cache should be active.
`// Cache implementation example
const directus = createDirectus(process.env.NEXT_PUBLIC_API_URL || '').with(
rest({
onRequest: (options) => ({
...options,
next: {
revalidate: 3600,
tags: ['directus'],
},
}),
}),
);`
I also tried to use **unstable_cache**, works in DEV and not in PROD
Is this a known issue with Next.js 14 in standalone mode?
Does Next.js cache behave differently in production vs development?
Are there specific configurations needed to make cache work in standalone mode?
Thanks a tot!
does it work if you run the application in prod mode in your computer i.e. not in your infra?
i don't recall seeing caching completely breaks in standalone in production like that back in v14
i don't recall seeing caching completely breaks in standalone in production like that back in v14