admin管理员组文章数量:1290188
I recently started my new project with nextjs15 + supabase. I found out that from nextjs15 fetch function's default behavior is "no cache" which is different from version 14 when "force-cache" was default behavior.
Than I wondered how it works in my project. Most of my code uses supabase query function which looks like this.
(In server component)
const supabase = await createClient();
const {data, error} = await supabase.from("table_name").select(*);
In this case, is caching is automatically working just like nextjs14 fetch function? If it is not, then how can i apply caching strategy in this supabase project?
I tried writing code
export const revalidate = 60;
at the top of my page.tsx file where it fetches data from supabase, but it seems like it doesn't work because whenever I insert new data to my db, the data is shown immediately(before 1 minute pass).
I recently started my new project with nextjs15 + supabase. I found out that from nextjs15 fetch function's default behavior is "no cache" which is different from version 14 when "force-cache" was default behavior.
Than I wondered how it works in my project. Most of my code uses supabase query function which looks like this.
(In server component)
const supabase = await createClient();
const {data, error} = await supabase.from("table_name").select(*);
In this case, is caching is automatically working just like nextjs14 fetch function? If it is not, then how can i apply caching strategy in this supabase project?
I tried writing code
export const revalidate = 60;
at the top of my page.tsx file where it fetches data from supabase, but it seems like it doesn't work because whenever I insert new data to my db, the data is shown immediately(before 1 minute pass).
Share Improve this question asked Feb 20 at 4:13 Developer DDeveloper D 234 bronze badges1 Answer
Reset to default 1Most of the data caching strategies in next.js server components are implemented as an extension of the native fetch function. The supabase SDK uses mostly postgres connections to get data so the caching will likely not work out of the box.
A good strategy would be to create an API route where you fetch your data from postgres and call this endpoint in your server component using fetch. Most of the magic happens in headers so this way you would have them implemented automatically.
https://nextjs./docs/app/building-your-application/data-fetching/fetching
Another alternative could be to use the cache function from react that is native to server components (not a next.js specific)
https://react.dev/reference/react/cache
This could wrap your call and provide caching.
本文标签: nextjsDoes caching works in supabasenextjs15Stack Overflow
版权声明:本文标题:next.js - Does caching works in supabase + nextjs15? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741459008a2379925.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论