#Question on Opting out of Data Caching

1 messages · Page 1 of 1 (latest)

clear portalBOT
#

Hi @mental holly. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

No, this function would not opt you out of caching. In fact, it includes a caching strategy. The line next: { revalidate: 60 } in your fetch options is a directive for Next.js to revalidate the data at most every 60 seconds. This means that the data will be fetched from the external data source and stored in the Data Cache the first time the fetch request is called. Any requests that are called within the next 60 seconds will return the cached data. After 60 seconds, the next request will still return the cached (now stale) data, but Next.js will trigger a revalidation of the data in the background. Once the data is fetched successfully, Next.js will update the Data Cache with the fresh data. If the background revalidation fails, the previous data will be kept unaltered. This is similar to stale-while-revalidate behavior (source (https://nextjs.org/docs/app/building-your-application/caching#data-cache)).

However, it's important to note that this caching strategy applies to server-side data fetching in Next.js. If your function ListWork is running on the client-side (in the browser), the next: { revalidate: 60 } option will not have any effect, as Next.js's caching and revalidation features are designed for server-side data fetching. If you need to cache data on the client-side, you would need to implement a different caching strategy, possibly using a state management library or the built-in caching mechanisms of the Fetch API or the browser.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@mental holly kapa.ai is still learning and improving, please let us know how it did by reacting below

mental holly
#
  const user = await currentUser();
  if (!user) return notFound();

  const combinedPromises = [
    ListCon(),
    ListWork()
  ];

  // Resolve all promises
  const [con, work] = await Promise.all(combinedPromises);

  return (
    <>
      <WorkTable con={con} work={work} />
    </>
  );
}``` Here's my page. WorkTable is a client component and the data show there. Would nextjs caching still work using next: { revalidate: 60 } or would that be considered client side and would need a client side strategy? @clear portal
clear portalBOT
#

Let me check the knowledge base for you. One moment! :books:

#

The next: { revalidate: 60 } option in your ListWork function would still apply in this context, as long as ListWork is being called during server-side rendering or static generation. This is because the next: { revalidate: 60 } option is a directive for Next.js's server-side data fetching and caching mechanisms.

However, once the data has been fetched and passed to your WorkTable component, any further updates to the data within that component would be happening on the client-side, and would not be affected by the next: { revalidate: 60 } option. If you need to update the data in your WorkTable component after the initial render, and you want to implement caching for those updates, you would need to implement a client-side caching strategy.

It's also worth noting that the next: { revalidate: 60 } option does not automatically update the data on the client-side when the revalidation happens on the server-side. The revalidated data would only be served to new requests for the page. If you want to update the data in your WorkTable component in real-time as the revalidation happens, you would need to implement a real-time data fetching strategy on the client-side, possibly using WebSockets, Server-Sent Events, or a similar technology.

In summary, the next: { revalidate: 60 } option can help improve the performance of your page by caching server-side data fetching, but it does not provide a complete solution for all data fetching and caching needs, especially on the client-side (source (https://nextjs.org/docs/app/building-your-application/caching)).

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: