Next.js Discord

Discord Forum

react.cache + revalidate segment config in RSC

Exotic Shorthair posted this in #help-forum
Open in Discord
Exotic ShorthairOP
Hi. I have an app directory page that uses searchParams for pagination. This should make the page dynamically rendered by default, but the database query (tRPC) is not getting called, even though segment config revalidate is set to 60 seconds.

There is the unstable_cache function, but this is not production ready. Is there a way to get this to work with react.cache? Or should this approach be avoided until there is better non-fetch cache support? If so what's the recommended data fetching pattern? Using a separate API to leverage fetch?

async function Page({ searchParams }: { cursor?: string, limit?: string }) {
  const result = await getOnSaleData(searchParams);
  // etc...

this will make a direct function call server side, not a fetch request (a database query):
import "server-only";
export const revalidate = 60; // 1 minutes

export const getOnSaleData = cache(
  async (options: RouterInputs["collection"]["getOnSale"]) => {
    return serverApi.collection.getOnSale.fetch(options);

0 Replies