Disable caching for API routes
Answered
Transvaal lion posted this in #help-forum
Transvaal lionOP
hi all, i wanna disable caching for almost all of my api routes, just wanna check if this const is enough to be in
layout.tsx or we need to apply it to all route.ts files where API is defined? I'm using 14.2.14 version of nextjs and app routerexport const fetchCache = 'force-no-store';Answered by B33fb0n3
you need to put it inside your route.ts. There you want to add
Like that it won't be cached
export const dynamic = 'force-dynamic'Like that it won't be cached
5 Replies
@Transvaal lion hi all, i wanna disable caching for almost all of my api routes, just wanna check if this const is enough to be in `layout.tsx` or we need to apply it to all `route.ts` files where API is defined? I'm using `14.2.14` version of nextjs and app router
`export const fetchCache = 'force-no-store';`
you need to put it inside your route.ts. There you want to add
Like that it won't be cached
export const dynamic = 'force-dynamic'Like that it won't be cached
Answer
Transvaal lionOP
gotcha! so there isn't a way to apply it globally but inside each
route.ts, right?@Transvaal lion gotcha! so there isn't a way to apply it globally but inside each `route.ts`, right?
yea, keep in mind, that that only applies to GET routes. POST, PUT, ... routes are all dynamic
@B33fb0n3 yea, keep in mind, that that only applies to GET routes. POST, PUT, ... routes are all dynamic
Transvaal lionOP
yup, understandable! thanks for the help
happy to help