You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First of all, thank you for this project. It's amazing. β€ It feels so good to be able to consume WP content with nextjs.
So i'm having some problems trying to work around the rather aggressive caching that nextjs does while developing locally. π
For example, when running the project locally, it would be amazing to be able to easily disable caching so that I can immediately see updates made to the wordpress cms.
// lib/wordpress.ts
...
constdefaultFetchOptions: FetchOptions={next: {tags: ["wordpress"],// revalidate: 3600, // Revalidate every hour by defaultrevalidate: 0,cache: "no-store",},};
Still, i cannot get nextjs to purge cache and show me non-stale wordpress post content. :(
Ive also tried creating an api route to purge cache - this does not work either (i refresh the page after calling this API - and nothing changes - i still see stale WP post content
// app/api/clear-cache/route.tsximporttype{NextRequest}from"next/server";import{revalidateWordPressData}from"../../../lib/wordpress";exportasyncfunctionPOST(request: NextRequest){try{awaitrevalidateWordPressData(["wordpress","post","posts","post-hello-world",]);console.log("@@@@@@@@@ CACHE CLEARED @@@@@@@@@");returnResponse.json({message: "Successfully revalidated all WP data"});}catch(e: unknown){console.error("Cache clear error:",e);returnResponse.json({message: "Failed to clear cache"},{status: 500});}}
About the only thing that has worked so far is to modify the base wordpressFetch function:
// lib/wordpress.tsasyncfunctionwordpressFetch<T>(url: string,options: FetchOptions={}): Promise<T>{constuserAgent="Next.js WordPress Client";// Add timestamp to URL to prevent cachingconsttimestampedUrl=`${url}${url.includes("?") ? "&" : "?"}_ts=${Date.now()}`;constresponse=awaitfetch(timestampedUrl,{// modify the url each time its being made, to ensure its never cached.
...defaultFetchOptions,
...options,headers: {"User-Agent": userAgent,},});
But this solve feels a little like the nuclear option. Is there something i'm missing?
The text was updated successfully, but these errors were encountered:
glomotion
changed the title
Problems with caching
Problems with local dev & caching
Feb 16, 2025
glomotion
changed the title
Problems with local dev & caching
Problems with local dev caching
Feb 16, 2025
Hello there π
First of all, thank you for this project. It's amazing. β€ It feels so good to be able to consume WP content with nextjs.
So i'm having some problems trying to work around the rather aggressive caching that nextjs does while developing locally. π
For example, when running the project locally, it would be amazing to be able to easily disable caching so that I can immediately see updates made to the wordpress cms.
i've also tried adding:
And i have tried setting:
Still, i cannot get nextjs to purge cache and show me non-stale wordpress post content. :(
Ive also tried creating an api route to purge cache - this does not work either (i refresh the page after calling this API - and nothing changes - i still see stale WP post content
About the only thing that has worked so far is to modify the base wordpressFetch function:
But this solve feels a little like the nuclear option. Is there something i'm missing?
The text was updated successfully, but these errors were encountered: