Repository navigation
|
It's public knowledge that Next.js does not have a native feature for invalidating cache of static, SSG, ISG or ISR pages on demand, which could be used with an API for triggering content update without having to rebuild the application, although maintainers had already demonstrated interest in implementing it (see here and here). Many people are asking for a solution or workaround for this (e.g. #21903 and #16488). Until an official implementation, I'd like to suggest setting a custom server to ask Next.js to delete prerendering files and purging LRU Cache for a specific URL, by just appending the parameter There's a serious caveat, though: it cannot be deployed to Vercel. The code is below and also published in this repo. I'd appreciate any contributions or ideas about this proposal. |
Replies: 12 comments 34 replies
|
Have you tested the code above and it works? |
|
Thanks a lot for the code snippet @FSaldanha! This feature is definitively something that would help. Also, another alternative is to delete the entry from the try {
await promises.unlink(fullPathHTML);
await promises.unlink(fullPathJSON);
const cachedData = await app.incrementalCache.get(pathname);
const staleTime = new Date().getTime() - 1000;
/* Delete the entry in cache */
app.incrementalCache.cache.del(pathname);
console.log(`Cache of ${fullPathname} was successfully purged`);
} catch (err) {
console.error(`Could not purge cache of ${fullPathname} - ${err}`);
} |
|
something like this is really needed when deploying on Vercel |
|
In Next.js 10.2 |
|
I tested it locally with express and works for me. In this way, it updates the page on the next visit. server.js in node_modules\next\dist\next-server\server\incremental-cache.js |
|
@FSaldanha one thing to ask, the solution you provided has a path to the ./next folder in your nextjs project, what i currently have is my entire backend in different space (let's say hosted on AWS), so is there a way i could run this solution in main file of backend (which is already hosted on AWS) and provide a path to ./next folder anyhow? or i should add this particular solution to server.js file inside next project ?? |
|
When using the above code, I get the following error: I'm having some trouble debugging it. for me it's also not rebuilding the file but just serving the cached file instead. |
|
I also agree with @FSaldanha that there is a need for this feature. The possibility to clear a cache with the path (e.g. for example letΒ΄s say you have a resource that gives you data e.g. GET |
|
Hi, I've thought of a possible alternative, based on route params:
Timestamp changes will retrigger a render, as if it was a new article in the example of a blog. Which makes sense, as it is a new version of the article. Pros:
Downsides:
|
|
My website has millions of pages. And I dunno how to clear cache when my pages are changed. |
|
I'm incredibly excited to share that Next.js 12.1 was just released, which includes on-demand Incremental Static Regeneration! We know many of you have been looking forward to this for a while, including myself, and I'm so happy it is here. |
|
Is there any update on this issue? I don't really wanna have to validate multiple pages. I only want to delete those pages and validate them when the client sends a request. |
I'm incredibly excited to share that Next.js 12.1 was just released, which includes on-demand Incremental Static Regeneration! We know many of you have been looking forward to this for a while, including myself, and I'm so happy it is here.