Skip to content

Commit 59873d7

Browse files
Jean LauliacFacebook Github Bot
Jean Lauliac
authored and
Facebook Github Bot
committed
packager: Module: gives global cache more retries
Reviewed By: cpojer Differential Revision: D4250880 fbshipit-source-id: c2d215d4dad10705bc24bec758aed85ef13607ba
1 parent cb254d1 commit 59873d7

File tree

1 file changed

+11
-9
lines changed
  • packager/react-packager/src/node-haste

1 file changed

+11
-9
lines changed

packager/react-packager/src/node-haste/Module.js

+11-9
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class Module {
7474
_readSourceCodePromise: Promise<string>;
7575
_readPromises: Map<string, Promise<ReadResult>>;
7676

77-
static _useGlobalCache: boolean;
77+
static _globalCacheRetries: number;
7878

7979
constructor({
8080
file,
@@ -235,21 +235,23 @@ class Module {
235235
callback: (error: ?Error, result: ?TransformedCode) => void,
236236
) {
237237
const globalCache = GlobalTransformCache.get();
238-
if (!Module._useGlobalCache || globalCache == null) {
238+
if (Module._globalCacheRetries <= 0 || globalCache == null) {
239239
this._transformCodeForCallback(cacheProps, callback);
240240
return;
241241
}
242242
globalCache.fetch(cacheProps, (globalCacheError, globalCachedResult) => {
243-
if (globalCacheError != null && Module._useGlobalCache) {
243+
if (globalCacheError != null && Module._globalCacheRetries > 0) {
244244
console.log(chalk.red(
245245
'\nWarning: the global cache failed with error:',
246246
));
247247
console.log(chalk.red(globalCacheError.stack));
248-
console.log(chalk.red(
249-
'The global cache will be DISABLED for the ' +
250-
'remainder of the transformation.',
251-
));
252-
Module._useGlobalCache = false;
248+
Module._globalCacheRetries--;
249+
if (Module._globalCacheRetries <= 0) {
250+
console.log(chalk.red(
251+
'No more retries, the global cache will be disabled for the ' +
252+
'remainder of the transformation.',
253+
));
254+
}
253255
}
254256
if (globalCacheError != null || globalCachedResult == null) {
255257
this._transformCodeForCallback(cacheProps, callback);
@@ -353,7 +355,7 @@ class Module {
353355
}
354356
}
355357

356-
Module._useGlobalCache = true;
358+
Module._globalCacheRetries = 4;
357359

358360
// use weak map to speed up hash creation of known objects
359361
const knownHashes = new WeakMap();

0 commit comments

Comments
 (0)