add filesystem caching with cacache

This commit is contained in:
Randall Schmidt
2021-07-05 21:40:53 -04:00
parent e8ad8da0bb
commit 6cd42272c4
5 changed files with 268 additions and 35 deletions

View File

@ -91,8 +91,16 @@ async function getResponse(cache, requestArguments) {
const fetchResponse = await fetch(...requestArguments);
const nfcResponse = NFCResponse.fromNodeFetchResponse(fetchResponse, ejectSelfFromCache);
const contentLength = Number.parseInt(nfcResponse.headers.get('content-length'), 10) || 0;
const nfcResponseSerialized = nfcResponse.serialize();
await cache.set(cacheKey, nfcResponseSerialized.bodyStream, nfcResponseSerialized.metaData);
await cache.set(
cacheKey,
nfcResponseSerialized.bodyStream,
nfcResponseSerialized.metaData,
contentLength,
);
return nfcResponse;
}