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)
|
||||
*/
|
||||
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)
|
||||
*/
|
||||
|
|
|
@ -126,6 +126,7 @@ class FileCachePlugin {
|
|||
? { debug: 4, verbose: 3, info: 2, warning: 1 }[this.options.loglevel]
|
||||
: 0;
|
||||
const store = this.options.store || "pack";
|
||||
const idleTimeout = this.options.idleTimeout || 0;
|
||||
|
||||
const resolvedPromise = Promise.resolve();
|
||||
|
||||
|
@ -364,11 +365,19 @@ class FileCachePlugin {
|
|||
}
|
||||
}
|
||||
};
|
||||
let idleTimer = undefined;
|
||||
compiler.cache.hooks.beginIdle.tap("FileCachePlugin", () => {
|
||||
isIdle = true;
|
||||
resolvedPromise.then(processIdleTasks);
|
||||
idleTimer = setTimeout(() => {
|
||||
idleTimer = undefined;
|
||||
isIdle = true;
|
||||
resolvedPromise.then(processIdleTasks);
|
||||
}, idleTimeout);
|
||||
});
|
||||
compiler.cache.hooks.endIdle.tap("FileCachePlugin", () => {
|
||||
if (idleTimer) {
|
||||
clearTimeout(idleTimer);
|
||||
idleTimer = undefined;
|
||||
}
|
||||
isIdle = false;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -168,6 +168,11 @@
|
|||
"description": "Algorithm used for generation the hash (see node.js crypto package)",
|
||||
"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": {
|
||||
"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"]
|
||||
|
|
Loading…
Reference in New Issue