admin管理员组文章数量:1387360
How can i display on the page the moment the cache was generated?
using nextjs15.
something like:
// app/page.tsx
import cache from '@next/something'
...
return ("<p>page was generated on {cache.timestamp}></p>")
How can i display on the page the moment the cache was generated?
using nextjs15.
something like:
// app/page.tsx
import cache from '@next/something'
...
return ("<p>page was generated on {cache.timestamp}></p>")
Share
Improve this question
asked Mar 18 at 20:14
gcbgcb
14.6k9 gold badges71 silver badges96 bronze badges
1 Answer
Reset to default 1If you specifically need to know when Next.js last built a static page, you could store the build timestamp in an environment variable at build time and access it in your page. Would be better in this case..
Additionaly you can use the built-in generateMetadata
like this example:
// get current server timestamp
function getTimestamp() {
return new Date().toLocaleString();
}
export default function Page() {
// frozen at time your app build for static pages
// or evaluated at request time for dynamic pages *see the end lines*
const timestamp = getTimestamp();
return (
<div>
<h1>Your next Page</h1>
<p>Page was generated on: {timestamp}</p>
{/* Rest of your page content */}
</div>
);
}
// To ensure the page is dynamic and shows the actual render time
export const dynamic = 'force-dynamic';
// To revalidate at in intervals
export const revalidate = 60; // revalidate every x seconds
And for a more advance feature you can add in as a Server Component context.
本文标签: nextjsHow to get the timestamp of a nextjs cache entryStack Overflow
版权声明:本文标题:next.js - How to get the timestamp of a nextjs cache entry? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744492801a2608838.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论