fetch() data cache clarification
Unanswered
Asian black bear posted this in #help-forum
Asian black bearOP
I have some HTTP requests that need to be cached for say, 12 hours. These requests get executed after cookies are read.
Originally I was using
I removed the
In the first image, the top two requests are being cached:
The bottom request is also being cached but is a POST request. The docs say that fetch won't cache when called /after/ cookie access, but I'm absolutely sure this used to work just fine.
In image 2, this is what Request Metrics looked like for the same route before I made these changes. I've drawn which cache call corresponds to which request. If the cache was hit, why are the requests still seemingly executing?
I'm on 14.2.3. In local dev, I can see logging show cache hits. Is Vercel just not showing data cache stuff as soon as the log is made?
Originally I was using
unstable_cache to bundle two of these requests into one and cache them, but I noticed that in my Vercel log Request Metrics that the requests were seemingly still firing while also pulling from the cache. Because for whatever reason, unstable_cache data cache reads only show up as "undefined" in the usage panel, I decided to try just use fetch() caching so I could see the URL in the usage panel.I removed the
unstable_cache call and now my Request Metrics are showing requests firing every time with nothing about the cache. Neither URL are appearing in my data cache usage panel.In the first image, the top two requests are being cached:
fetch(`.../${myVar}`, {
next: {
revalidate: 60 * 60 * 12,
tags: ["my-tag", myVar],
}
})The bottom request is also being cached but is a POST request. The docs say that fetch won't cache when called /after/ cookie access, but I'm absolutely sure this used to work just fine.
In image 2, this is what Request Metrics looked like for the same route before I made these changes. I've drawn which cache call corresponds to which request. If the cache was hit, why are the requests still seemingly executing?
I'm on 14.2.3. In local dev, I can see logging show cache hits. Is Vercel just not showing data cache stuff as soon as the log is made?
2 Replies
Asian black bearOP
ok yeah I'm absolutely sure the cache just isn't working. I'm seeing logs of a fetch failing (remote host fail, expected) but it should have been cached for another 11 hours at this point. Is it straight up just not possible to fetch() cache after reading cookies? I cannot run these request before reading cookies without introducing a waterfall. The requests don't rely on the cookie, however.
Asian black bearOP
I just switched these fetch() requests back over to unstable_cache() and now Request Metrics is displaying the cache hit properly, the requests aren't firing and function execution duration has dropped. Is there a reason why fetch() caching used to work just fine despite reading cookies?