Next.js Discord

Discord Forum

'use cache: private': i don't know what is wrong or if is an issue this is not working for me

Unanswered
Lionhead posted this in #help-forum
Open in Discord
LionheadOP
This was my test setup


const Privatecache = async ({ userid }: { userid: string }) => { 'use cache: private' cacheLife({ stale: 86400, // 1 day in seconds revalidate: 172800, // 2 days expire: 604800 // 7 days }) console.log(Date.now(), ' - CACHE LIFETIME SET TO DAYS - DynamicDatacatched') const res = await fetch('http://localhost:4000/cache-open', { headers: { 'Content-Type': 'application/json', }, credentials: 'include' }) const { random, random2, now, date, uuid, bytes, user_id } = await res.json() return <UIdata title="Cached Data (Private Cache)" data={{ random, random2, now, date, uuid, bytes, user_id }} /> }

and
main page
<Suspense fallback={<p style={{ padding: '20px' }}>Loading...</p>}> <Privatecache userid="guest" /> </Suspense>

next.conf
const nextConfig: NextConfig = { cacheComponents: true, ...


Every time I refresh this page, it misses the cache and hits the server

2 Replies

Morelet’s Crocodile
on the dev server I dont think it caches? have you tried in prod or perview?
jw, would expire matter with use cache private as " Good to know: Unlike use cache, private caches are not prerendered statically as they contain personalized data that is not shared between users."