Next.js Discord

Discord Forum

Route segment revalidate option doesn't work with axios/react cache. Only unstable_cache works.

Unanswered
Sander posted this in #help-forum
Open in Discord
Avatar
SanderOP
Is this by design?

get this function:
const getTrackingData = unstable_cache(
  async (params: TrackingFormType) => {
    return await API.get<TrackingApiData>('/history', {
      params,
    });
  },
  undefined,
  {
    revalidate: 60,
  },
);

This works, the fetch requests are cached as the backend receives no extra requests.
However, the current recommended way is using import {cache} from 'react';
So this:
const getTrackingData = cache(async (params: TrackingFormType) => {
  return await API.get<TrackingApiData>('/history', {
    params,
  });
});

Doesn't work, it refetches everytime despite the route segment having export const revalidate=900;.
Am I missing something?

0 Replies