增量静态再生中的重新验证过程如何工作? [英] How does the revalidate process in Incremental Static Regeneration work?
问题描述
我有一个关于增量静态再生的问题.据我所知,getStaticProps()
函数中的 revalidate
值告诉 Next.js 它应该重建页面的时间量.
I have a question about the Incremental Static Regeneration. As far as I know the revalidate
value within the getStaticProps()
function tells Next.js the amount of time it should rebuild the pages.
我的问题是,在设定的时间后,每个用户/请求都会发生这种情况,还是集中,从第一个用户/请求点击页面开始?
My question about that is, will this happen for every user/request after the set amount of time, or centralized, starting with the first user/request hitting the page?
例如:
在 getStaticProps()
函数中重新验证值:60 秒
Revalidate value in the getStaticProps()
function: 60 seconds
用户 A 点击页面并接收缓存版本.60 秒后 Next.js 为他重建页面并提供新内容.
User A hits the page and receives a cached version. After 60 seconds Next.js rebuilds the pages for him and serves the fresh content.
用户 B 在用户 A 之后不久点击页面,收到缓存版本,60 秒后他还收到更新版本.
User B hits the page shortly after User A, receives a cached version and after 60 seconds he also receives an updated version.
我担心的是,每个单独的请求都会在 自己的 60 秒间隔内开始重建.
My concern is that every individual request starts it's own 60-second interval to rebuild.
我很确定情况并非如此,但由于 Next.js 对我来说是新的,我想在搞砸之前弄清楚这一点.
I'm quite sure that's not the case, but as Next.js is new to me, I wanted to get this straight before messing things up.
如果有人能自愿给予快速回复,我将非常感激.
I would be very thankful if somebody could volunteer to give a quick response.
推荐答案
增量静态生成受 stale-while-revalidate 启发,因此没有间隔.
假设我们的重新验证值为 60 秒:
Incremental static generation is Inspired by stale-while-revalidate, so there are no intervals.
Lets say that our revalidate value is 60 seconds :
- 第一个用户将在 100000000000(以毫秒为单位的随机时间)访问页面
- next.js 将缓存过期日期为 100000060000 的页面
- 其他用户来到 100000040000,缓存有效,什么都不做(服务缓存页面)
- 另一个访客在100000070000,缓存过期,next.js会在后台重新验证页面,但用户仍然看到旧页面.
- 最后一位访问者在 100000080000 出现,并将使用新数据设置页面
- 等等……
60 秒后 NextJS 为他重建页面并提供给新鲜的内容.
After 60 seconds NextJS rebuilds the pages for him and serves the fresh content.
所以没有这个概念是错误的,n 秒后next.js 不会重建页面,但是对于每个请求,next.js 将检查自上次请求以来经过的时间是否为 >即缓存的到期日期.如果您的 revalidate 值为 1 秒,但下一个访问者在 1 年后到来,则 next 将在一年后重新生成页面.
So no this concept is wrong, next.js will not rebuild the page after n seconds, but for every request next.js will check if the time elapsed since the last request is > that the expiry date of the cache. if your revalidate value is 1 second, but the next visitor comes after 1 year, next will regenerate the page after one year.
这篇关于增量静态再生中的重新验证过程如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!