mirror of https://github.com/webpack/webpack.git
add cache.idleTimeout option to delay cache storing
This commit is contained in:
parent
00065741d2
commit
e4a5e59570
|
@ -431,6 +431,10 @@ export interface FileCacheOptions {
|
||||||
* Algorithm used for generation the hash (see node.js crypto package)
|
* Algorithm used for generation the hash (see node.js crypto package)
|
||||||
*/
|
*/
|
||||||
hashAlgorithm?: string;
|
hashAlgorithm?: string;
|
||||||
|
/**
|
||||||
|
* Time in ms after which idle period cache storing should happen (only for store: 'pack' or 'idle')
|
||||||
|
*/
|
||||||
|
idleTimeout?: number;
|
||||||
/**
|
/**
|
||||||
* Display log info. (debug: all access and errors with stack trace, verbose: all access, info: all write access, warning: only failed serialization)
|
* Display log info. (debug: all access and errors with stack trace, verbose: all access, info: all write access, warning: only failed serialization)
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -126,6 +126,7 @@ class FileCachePlugin {
|
||||||
? { debug: 4, verbose: 3, info: 2, warning: 1 }[this.options.loglevel]
|
? { debug: 4, verbose: 3, info: 2, warning: 1 }[this.options.loglevel]
|
||||||
: 0;
|
: 0;
|
||||||
const store = this.options.store || "pack";
|
const store = this.options.store || "pack";
|
||||||
|
const idleTimeout = this.options.idleTimeout || 0;
|
||||||
|
|
||||||
const resolvedPromise = Promise.resolve();
|
const resolvedPromise = Promise.resolve();
|
||||||
|
|
||||||
|
@ -364,11 +365,19 @@ class FileCachePlugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
let idleTimer = undefined;
|
||||||
compiler.cache.hooks.beginIdle.tap("FileCachePlugin", () => {
|
compiler.cache.hooks.beginIdle.tap("FileCachePlugin", () => {
|
||||||
isIdle = true;
|
idleTimer = setTimeout(() => {
|
||||||
resolvedPromise.then(processIdleTasks);
|
idleTimer = undefined;
|
||||||
|
isIdle = true;
|
||||||
|
resolvedPromise.then(processIdleTasks);
|
||||||
|
}, idleTimeout);
|
||||||
});
|
});
|
||||||
compiler.cache.hooks.endIdle.tap("FileCachePlugin", () => {
|
compiler.cache.hooks.endIdle.tap("FileCachePlugin", () => {
|
||||||
|
if (idleTimer) {
|
||||||
|
clearTimeout(idleTimer);
|
||||||
|
idleTimer = undefined;
|
||||||
|
}
|
||||||
isIdle = false;
|
isIdle = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,6 +168,11 @@
|
||||||
"description": "Algorithm used for generation the hash (see node.js crypto package)",
|
"description": "Algorithm used for generation the hash (see node.js crypto package)",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"idleTimeout": {
|
||||||
|
"description": "Time in ms after which idle period cache storing should happen (only for store: 'pack' or 'idle')",
|
||||||
|
"type": "number",
|
||||||
|
"minimum": 0
|
||||||
|
},
|
||||||
"loglevel": {
|
"loglevel": {
|
||||||
"description": "Display log info. (debug: all access and errors with stack trace, verbose: all access, info: all write access, warning: only failed serialization)",
|
"description": "Display log info. (debug: all access and errors with stack trace, verbose: all access, info: all write access, warning: only failed serialization)",
|
||||||
"enum": ["debug", "verbose", "info", "warning"]
|
"enum": ["debug", "verbose", "info", "warning"]
|
||||||
|
|
Loading…
Reference in New Issue