#fetch() data cache clarification

3 messages · Page 1 of 1 (latest)

brisk folio
#

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 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?

fluid breachBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

brisk folio
#

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.