Permalink
Browse files

packager: GlobalTransformCache: cache the transform options digest

Reviewed By: davidaurelio

Differential Revision: D4906974

fbshipit-source-id: b6cf83ba6a072400685948329070e171f65c837d
  • Loading branch information...
jeanlauliac authored and facebook-github-bot committed Apr 19, 2017
1 parent 9dc7654 commit de3478c1b1a6516e7609d93dc328df2f37066c05
@@ -225,7 +225,7 @@ class URIBasedGlobalTransformCache {
keyOf(props: FetchProps) {
const hash = crypto.createHash('sha1');
const {sourceCode, filePath, transformOptions} = props;
this._optionsHasher.hashTransformWorkerOptions(hash, transformOptions);
hash.update(this._optionsHasher.getTransformWorkerOptionsDigest(transformOptions));
const cacheKey = props.getTransformCacheKey(sourceCode, filePath, transformOptions);
hash.update(JSON.stringify(cacheKey));
hash.update(crypto.createHash('sha1').update(sourceCode).digest('hex'));
@@ -313,9 +313,23 @@ class URIBasedGlobalTransformCache {
class OptionsHasher {
_rootPath: string;
_cache: WeakMap<TransformWorkerOptions, string>;
constructor(rootPath: string) {
this._rootPath = rootPath;
this._cache = new WeakMap();
}
getTransformWorkerOptionsDigest(options: TransformWorkerOptions): string {
const digest = this._cache.get(options);
if (digest != null) {
return digest;
}
const hash = crypto.createHash('sha1');
this.hashTransformWorkerOptions(hash, options);
const newDigest = hash.digest('hex');
this._cache.set(options, newDigest);
return newDigest;
}
/**
@@ -19,12 +19,12 @@ Object {
exports[`GlobalTransformCache fetches results 1`] = `
Array [
Object {
"code": "/* code from http://globalcache.com/fb94b11256237327e4eef5daa08bad33573b3781-foo.js */",
"code": "/* code from http://globalcache.com/43e279be6916de8be463ef98bd72ded391608371-foo.js */",
"dependencies": Array [],
"dependencyOffsets": Array [],
},
Object {
"code": "/* code from http://globalcache.com/b902b4a8841fcea2919c2fe9b21e68d96dff59c9-bar.js */",
"code": "/* code from http://globalcache.com/e09598ad4c807cb22b32d68cfc16e0cba7fdb85c-bar.js */",
"dependencies": Array [],
"dependencyOffsets": Array [],
},

0 comments on commit de3478c

Please sign in to comment.