cloudflare / cloudflare/workerd
🐛 BUG: Inconsistent behavior with pages functions runtime for cache deletion in `wrangler pages dev`
- Dominant language
- C++
- Stars
- 8.7k
- Forks
- 739
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 174
Description
### Which Cloudflare product(s) does this pertain to?
Pages
### What version of `Wrangler` are you using?
2.11.0
### What operating system are you using?
macos 13.1
### Describe the Bug
In pages functions, wrangler would allow to delete a certain kind of cache entries while the real runtime won't. The code is like
```ts
static async delete(cache: ManagedCache, key: string) {
try {
await cache.cache.delete(key)
} catch (e) {
logger.log('[cache][workaround]', cache.name, key, String(e))
await this.put(cache, key, new Response('', { headers: { DELETED: 'DELETED', 'Expires': new Date(0).toUTCString() } }))
}
}
```
`Wrangler` won't throw on the `await cache.delete(key)` line, while the actual runtime always throws `Error: unable to delete cached response`. (and fallback to the workaround, the workaround works though).
The cache entry was added like:
```ts
static async put(cache: ManagedCache, key: string, resp: Response): Promise {
const headers = new Headers(resp.headers)
if (!headers.has('Expires') && !headers.has('Cache-Control')) {
headers.set('Expires', new Date(cache.expires + Date.now()).toUTCString())
}
const putted = new Response(resp.clone().body, { headers })
await cache.cache.put(key, putted)
return
}
```
And inside `.wrangler/state/cache`, it looks like:
```json
{
"key": "",
"expiration": 1677275323,
"metadata": {
"status": 200,
"headers": [
[
"access-control-allow-headers",
"Content-Type, Authorization"
],
[
"access-control-allow-methods",
"OPTIONS,POST,GET"
],
[
"access-control-allow-origin",
"http://localhost"
],
[
"connection",
"keep-alive"
],
[
"content-length",
""
],
[
"content-type",
"application/json"
],
[
"date",
"Thu, 23 Feb 2023 21:48:43 GMT"
],
[
"expires",
"Fri, 24 Feb 2023 21:48:43 GMT"
],
[
"via",
"1.1 .cloudfront.net (CloudFront)"
],
[
"x-amz-apigw-id",
""
],
[
"x-amz-cf-id",
""
],
[
"x-amz-cf-pop",
""
],
[
"x-amzn-requestid",
""
],
[
"x-amzn-trace-id",
""
],
[
"x-cache",
"Miss from cloudfront"
]
]
}
}
```
(the amazon fields are from upstream, I don't know whether they would be relevant so I would just put them there).
I am not sure whether this is a bug for the real runtime or for workers-sdk. There is a discussion for it at discord id 1074116255134535700 (workers-help > cannot delete cache entries) in cloudflare server.
Contributor guide
Assessment
This issue has not been assessed yet.