Trying to make a simple cache using a cloudflare worker with hono.
I was wondering if anyone could assist me with what I thought was going to be a simple usage of the cache api.
My issue is that I cannot seem to get the cache to store the body properly...
The cache key is getting stored and properly invalidated after 10 seconds but the body is always an empty object when the cache is matched.
The logs are showing up as this with an empty body when hitting the cache.
2 Replies
console.log('body', JSON.stringify(response?.body))
will never show anything
body
is a ReadableStream and you can't serialise that
If you want a text body, do await response.text()
- or an object from JSON, await response.json()
@kiannh Thank you. I got it working like this.
I wasn't able to directly return the response and I've also tried with response.clone().
Is there something I'm missing here?