nitro
nitro copied to clipboard
Caching fails when returning a Buffer (PNG image)
Environment
Node: 18.18 Nitro: latest
Reproduction
- open Stackblitz
- open dev tools and disable cache in network tab
- click the reload button in the preview multiple times
Expected: 2 logos should be visible
Actual result: the second logo using the cached route breaks when reloading in between 5s (since the cache max age is set to 5s)
Describe the bug
Use case
I do want to return a dynamically generated PNG image in a Nitro route. This works fine in general.
Issue
I also would like to add caching using cachedEventHandler
. But all requests that should return a cached response, return the serialised JSON instead of the binary data, e.g. {"type": "Buffer", "data": [137,80,78,71,13,10,26,10,0,...
Additional context
I guess it's related to https://github.com/unjs/unstorage/issues/142 and the Nitro Cache should use setItemRaw()
/getItemRaw()
for the case of a Buffer?
Logs
No response