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
Let's suppose my endpoint has changing data that takes time to (re)generate.
I use stale-while-revalidate in Cache-Control so the Vercel Edge Cache returns its stale data while refreshing.
According to this docGET /api/data will either respond with
some stale data with X-Vercel-Cache set to STALE
some fresh data with X-Vercel-Cache set to either MISS, HIT, REVALIDATED, BYPASS
some static data with X-Vercel-Cache set to PRERENDER
The proposal is that if the response is stale (STALE), the SWR library will force revalidate every X seconds until it gets the latest fresh data (HIT).
This way, the client always gets some data to deal with, and it gets the latest fresh data when it's ready.
Here is how I see the config:
useSWR(...,{refreshStaleInterval: 5// seconds to wait before each request})
Is some sense, it behaves like refreshInterval excepts it stops itself when it gets fresh data.
This discussion was converted from issue #1820 on December 20, 2022 15:28.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Let's suppose my endpoint has changing data that takes time to (re)generate.
I use
stale-while-revalidate
inCache-Control
so the Vercel Edge Cache returns its stale data while refreshing.According to this doc
GET /api/data
will either respond withX-Vercel-Cache
set toSTALE
X-Vercel-Cache
set to eitherMISS
,HIT
,REVALIDATED
,BYPASS
X-Vercel-Cache
set toPRERENDER
The proposal is that if the response is stale (
STALE
), the SWR library will force revalidate every X seconds until it gets the latest fresh data (HIT
).This way, the client always gets some data to deal with, and it gets the latest fresh data when it's ready.
Here is how I see the config:
Is some sense, it behaves like
refreshInterval
excepts it stops itself when it gets fresh data.Beta Was this translation helpful? Give feedback.
All reactions