Skip to content

Caching fails when returning a Buffer (PNG image) #1894

@jschroeter

Description

@jschroeter

Environment

Node: 18.18
Nitro: latest

Reproduction

  1. open Stackblitz
  2. open dev tools and disable cache in network tab
  3. 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 unjs/unstorage#142 and the Nitro Cache should use setItemRaw()/getItemRaw() for the case of a Buffer?

Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions