jaredwray/cacheable

Special handling of binary files?

Closed this issue · 2 comments

Gatsby has a file downloading API. We're looking at making the cache smarter (we only look at etags right now) gatsbyjs/gatsby#31408 to avoid making any request if the remote asset set e.g. cache-control headers.

What we're trying to figure out with Got/cachable-request is if it's possible to a) handle storing request bodies ourselves (we need the actual file written to disk) and b) skip the request altogether if the cache is still valid (it seems Got would still try to stream the request body regardless?).

It might be we need to go down another layer and implement this ourselves with http-cache-semantics (which is fine) but we're curious first if this is solvable with vanilla got/cachable-request.

Thanks for all your great work on these libraries!

I think storing request bodies could be done if cacheable-request (and got) exposed an api to configure the Keyv serialiser/deserializer to use an identity function - then gatsby could handle the raw data in the cache adapter.

The stream got returns for a cached entry provides a isFromCache boolean prop so gatsby can ignore the response in that case.

@cameronbraid - can you give an example of what you would like to see from Got and this library?