Next.js Discord

Discord Forum

Dynamic api route.ts cache? TTL?

Unanswered
Tamaskan Dog posted this in #help-forum
Open in Discord
Avatar
Tamaskan DogOP
I've searched a lot of the docs, and this discord, and it seems like most people have questions about how to enable dynamic routing cache for a SSR Page.

In my case, I have a client component, and I am fetching from a dynamic route.ts

GET /api/showcase/[showcaseId]/route.ts

I would like to put a TTL or revalidation of say 30-60 seconds on this routes response. So if the same slug is hit back to back, it will have the same response. I've tried a few things from the docs but nothing seems to work right?

i.e.:
export const revalidate = 120;
export const dynamic = 'force-static'


I'd also prefer this be a server side cache, it does work as a client side cache when I manually set Cache-Control, but I'd like to cache it for all users at once.

Any help or docs to read would be great.

2 Replies

Avatar
Tamaskan DogOP
I know that from the docs caching is NOT enabled by default for dynamic routes.
Avatar
Ray
GET endpoint if static by default, I think export const revalidate = 120; should do what you want?