无法使用RTK查询重置Next.js中的缓存

dwbf0jvd  于 2023-08-04  发布在  其他
关注(0)|答案(1)|浏览(97)

我使用Next.js与next-redux-wrapper和RTK查询。我的应用程序正在服务器端进行外部API调用。我以这种方式实现了这个请求:

CompaniesPage.getInitialProps = initialPagePropsWithCompanies;

// ---
import { createWrapper } from 'next-redux-wrapper';

const wrapper = createWrapper<ReturnType<typeof makeStore>>(makeStore);
export const initialPagePropsWithCompanies = wrapper.getInitialPageProps((store: AppStore) => async () => {
  store.dispatch(api.endpoints.getHomePage.initiate());
  await Promise.all(store.dispatch(api.util.getRunningQueriesThunk()));
  return { props: {} };
});

字符串
问题是响应被缓存在Next.js的某个地方。我不知道如何禁用它,或减少寿命。
1.我的页面上有export const revalidate = 5;
1.我已经将cache: 'no-store'添加到fetchBaseQuery配置中:

baseQuery: fetchBaseQuery({
    baseUrl: `${process.env.NEXT_PUBLIC_PROTOCOL || 'https://'}${process.env.NEXT_PUBLIC_VERCEL_URL}/api`,
    headers: {
      'x-telegram-query': typeof window !== 'undefined' ? window.Telegram.WebApp.initData : '',
    },
    cache: 'no-store',
  }),


1.我还尝试将next: { revalidate: 5 }添加到fetchBaseQuery配置中。
什么都帮不🥲上忙。我什么都不知道。任何人都可以给予建议吗?

w8biq8rn

w8biq8rn1#

你可以这样做。forceRefetch

export const revalidate = 0;

const HomePage = async () => {
  const { data } = await store.dispatch(
    articlesApi.endpoints.getArticles.initiate(
      { id: 2 },
      {
        forceRefetch: true,
      }
    )
  );
  return (
    <div></div>
  );
};

字符串

相关问题