async-disk-cache
async-disk-cache copied to clipboard
How do I store binary objects and streams?
Can't find any info... Any help would be appreciated.
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?
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')
I see, that is not currently supported, but could be. Unclear if I have time to do so, but would welcome a PR.