async-disk-cache icon indicating copy to clipboard operation
async-disk-cache copied to clipboard

How do I store binary objects and streams?

Open alex-jitbit opened this issue 5 years ago • 3 comments

Can't find any info... Any help would be appreciated.

alex-jitbit avatar Mar 20 '20 20:03 alex-jitbit

Today, if you wanted to cache a binary object that would be as a buffer, and enabled via supportBuffer: true. I'm not really sure what it means to cache a stream to disk, can you share more?

stefanpenner avatar Jun 23 '20 22:06 stefanpenner

for streaming, i think what they're after is something like:

const readStream = createReadStream(...);
cache.set('foo', readStream).then(function() {
  // readStream was read and closed, and stream written to foo
});

// or possibly/also

readStream.pipe(cache.setStream('foo'))

and that way the contents of foo is never buffered in memory. consider the scenario where you're caching 100mb files on a server with 1g of memory. that should be possible but won't be without stream support.

you'd also need the read stream counterpart for it to be useful, e.g.: cache.getStream('foo')

cmawhorter avatar Dec 03 '20 17:12 cmawhorter

I see, that is not currently supported, but could be. Unclear if I have time to do so, but would welcome a PR.

stefanpenner avatar Dec 08 '20 01:12 stefanpenner