Environment
##Reproduction env:
- Stackblitz
- Nitro v2.8.1
- Node v18.18.0
Env where encountered
- Operating System: Linux
- Node Version: v18.17.1
- Nuxt Version: 3.8.1
- CLI Version: 3.9.1
- Nitro Version: 2.7.2
- Package Manager: yarn@1.22.19
Reproduction
https://stackblitz.com/edit/github-wlae5p?file=routes%2Findex.ts
- Start the site either with
npm run dev or npm build && node .output/server/index.mjs
- Navigate to the
add-value-to-storage endpoint
- Navigate to the
swr endpoint (will see nitro: is-awesome)
- Navigate to the
not-swr endpoint (will see nitro: is-awesome)
- Navigate to the
remove-value-from-storage endpoint
- Navigate to the
not-swr route and refresh until the cache expires
- Will eventually get a blank response
- Navigate to the
swr endpoint
- It'll continue to return the
nitro: is-awesome response indefinitely.
Describe the bug
Routes cached by SWR cannot be updated to return empty/404 values without fully clearing the cache.
Description
We currently have a high-traffic Nuxt 3 site that's backed by a CMS. We have the pages and a Nuxt/Nitro API set to cache with SWR for 60 minutes.
When content editors delete a page, our CMS API will return null, which is what we'd expect our Nitro API to return. However, if the nitro API returns null or manually returns a 404 response, Nitro never seems to invalidate the SWR cache. This means we can't delete pages without manually clearing entries from the cache. This feels unexpected since there might be valid reasons for an API to return a 404 or 204 response.
Additional context
No response
Logs
No response
Environment
##Reproduction env:
Env where encountered
Reproduction
https://stackblitz.com/edit/github-wlae5p?file=routes%2Findex.ts
npm run devornpm build && node .output/server/index.mjsadd-value-to-storageendpointswrendpoint (will seenitro: is-awesome)not-swrendpoint (will seenitro: is-awesome)remove-value-from-storageendpointnot-swrroute and refresh until the cache expiresswrendpointnitro: is-awesomeresponse indefinitely.Describe the bug
Routes cached by SWR cannot be updated to return empty/404 values without fully clearing the cache.
Description
We currently have a high-traffic Nuxt 3 site that's backed by a CMS. We have the pages and a Nuxt/Nitro API set to cache with SWR for 60 minutes.
When content editors delete a page, our CMS API will return
null, which is what we'd expect our Nitro API to return. However, if the nitro API returnsnullor manually returns a 404 response, Nitro never seems to invalidate the SWR cache. This means we can't delete pages without manually clearing entries from the cache. This feels unexpected since there might be valid reasons for an API to return a 404 or 204 response.Additional context
No response
Logs
No response