Next.js Discord

Discord Forum

Caching in SSR

Unanswered
Peterbald posted this in #help-forum
Open in Discord
PeterbaldOP
I'm using nextjs w/ app directory for the first time and can't figure out caching in SSR.
If I'm rendering dynamic pages for a movie page(data fetched from a third party API - TMDB) via a slug, should I use caching for the API request? How to handle increased cache size during multiple such SSR requests? There are n number of movies, how will the cache handle that? Is there some middle of the road solution to handle this?

6 Replies

If I were you I'd be using next's time-based revalidation cache
// Revalidate at most every hour
fetch('https://...', { next: { revalidate: 3600 } })

It's like a perfect blend between preventing your cache size to grow too big and being able to serve mostly static content quick
PeterbaldOP
is there a way to opt caching for specified ids/slugs?
wdym by "opt caching"?
turn on caching on specific ids and slugs you mean? you could just set it to cache: "no-store" when the id is something that you don't want to cache
see the docs for more details