Comments (3)
I think you write cacheHandler by yourself here but it could be a little bit complicated, so I don't recommend you to write it by yourself.
Anyway, in your cacheHandler code there is not considering stale time strategy. So I think you have to add stale time handling in get function to update new value below.
async get(key) {
console.log('getting', key)
if (!this.cache[key]) return undefined
// This could be stored anywhere, like durable storage
const lastModified = this.cache[key].lastModified
const currentTime = Date.now()
const timeDiff = currentTime - lastModified
if (timeDiff < 3000) return this.cache[key]
// if data is Stale (3s), update
return undefined
}
Also see
from next.js.
@coffeecupjapan Thanks for your response! I am actually using this: https://caching-tools.github.io/next-shared-cache/redis but noticed the issue there so I reproduced it using my own cache handler as an example
I don't think thetimeDiff
helps. In the example you gave, the stale time is 3 seconds, however a more reasonable value for a static page might be 24 hours. However, what if I deploy a new version of the site with different content? The value will still be stuck at the old value for 24 hours. Looking at the cached value, it actually caches things like the <link
and <script
tags, however my newer deploy might have different names for those files. I first noticed this issue when I started getting 404's on my site and certain CSS and JS assets were failing to load
from next.js.
@nahtnam
OK. I see.
I looked into source code of @neshca/cache-handler
little bit, and come up with some ideas (however I have not tried on my local environment, and therefore it could be wrong).
There are two points on this issue.
The first point is that default cache time of this @neshca/cache-handler
seems like 1 year , so you might have to change this limitation by
return {
handlers: [redisHandler, localHandler],
ttl: { defaultStaleAge: 60 * 60 * 24 }
};
The second point is that this library seems like caching pageData
in .next/server/pages/${yourPageName}.html
and .next/server/pages/${yourPageName}.json
here
And read it here
So I think you can delete these caches ie .next/server/pages/${yourPageName}.html
and .next/server/pages/${yourPageName}.json
when you deploy, and prevent old values to be displayed.
Again, I have not tried in my local environment so it could be wrong, so if you find it not work please let me know.
from next.js.
Related Issues (20)
- Client side transition with middleware crashing
- `next build --debug` is breaking the output layout
- Inconsistency in Accessing URL Query Parameters Between `pages` and `app` Directories
- SSG pages with route rewrites request wrong files from _next/data HOT 1
- builds are non-deterministic (output file hashes change for no reason) HOT 2
- Next.js inside of Docker (with nginx) causes page to refresh every few minutes HOT 2
- Couldn't find all resumable slots by key/index during replaying. HOT 5
- Absolute Imports and Module Path Aliases not working in production with vercel HOT 4
- Error occurred prerendering page HOT 5
- [next-codemod] allow passing arguments to jscodeshift HOT 1
- The next.js option transpilePackages does not transpile inherited packages with Turbopack (--turbo)
- The icon does not appear on the home screen PWA app within startup HOT 2
- HTML children of MathML render in wrong namespace after routing HOT 1
- Problem running installation app due to multiple casing problem
- npm run dev is not working in termux HOT 1
- Docs: Add section about server actions to middleware documentation
- Cannot build with `typescript: 5.4.2`: Cannot find module 'next/dist/lib/metadata/types/metadata-interface.js' or its corresponding type declarations. HOT 3
- Dynamic import trace in page source HOT 6
- Error after enabling edge: `await isn't allowed in non-async function` HOT 1
- Swc android arm64 not working in termux HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from next.js.