Skip to content
This repository has been archived by the owner on Aug 20, 2024. It is now read-only.

Commit

Permalink
Cache stream packages
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Binns-Smith committed Sep 19, 2019
1 parent 33b61c3 commit d2f2ca0
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions packages/core/core/src/PackagerRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,15 @@ export default class PackagerRunner {
map
};

if (
cacheKey != null &&
// TODO This skips caching all packages that return Readable streams.
!(result.contents instanceof Readable)
) {
if (cacheKey != null) {
await this.writeToCache(cacheKey, result.contents, map);

if (result.contents instanceof Readable) {
return {
contents: this.options.cache.getStream(getContentKey(cacheKey)),
map: result.map
};
}
}

return result;
Expand Down Expand Up @@ -301,8 +304,8 @@ export default class PackagerRunner {
contents: Readable,
map: ?Readable
|}> {
let contentKey = md5FromString(`${cacheKey}:content`);
let mapKey = md5FromString(`${cacheKey}:map`);
let contentKey = getContentKey(cacheKey);
let mapKey = getMapKey(cacheKey);

let contentExists = await this.options.cache.blobExists(contentKey);
if (!contentExists) {
Expand All @@ -318,12 +321,12 @@ export default class PackagerRunner {
}

async writeToCache(cacheKey: string, contents: Blob, map: ?Blob) {
let contentKey = md5FromString(`${cacheKey}:content`);
let contentKey = getContentKey(cacheKey);

await this.options.cache.setStream(contentKey, blobToStream(contents));

if (map != null) {
let mapKey = md5FromString(`${cacheKey}:map`);
let mapKey = getMapKey(cacheKey);
await this.options.cache.setStream(mapKey, blobToStream(map));
}
}
Expand Down Expand Up @@ -410,3 +413,11 @@ function replaceReferences(

return output;
}

function getContentKey(cacheKey: string) {
return md5FromString(`${cacheKey}:content`);
}

function getMapKey(cacheKey: string) {
return md5FromString(`${cacheKey}:map`);
}

0 comments on commit d2f2ca0

Please sign in to comment.