Next.js Discord

Discord Forum

Invalidate cache and refresh data of specific segment or server function on page

Unanswered
Exotic Shorthair posted this in #help-forum
Open in Discord
Exotic ShorthairOP
I wonder if it is possible with server components to do the following:

Load a page with async data from a database. For example

/dashboard/admin/layout.tsx
export const getClients = cache(async () => {
  return await db.query.clients.findMany({
    columns: {
      id: true,
      logo: true,
      slug: true,
    },
  });
});


Now when this data gets mutated by some other part of the app, I want to not only invalidate the cache, but also reload this specific function. I am doing router.refetch now, but this reloads all the data on the page. How can I only refetch this specific function, or at least the specific route segment, similar to how you would call query.invalidate() in react-query.

0 Replies