Skip to content

Commit e4a5e59

Browse files
committed
add cache.idleTimeout option to delay cache storing
1 parent 0006574 commit e4a5e59

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

declarations/WebpackOptions.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,10 @@ export interface FileCacheOptions {
431431
* Algorithm used for generation the hash (see node.js crypto package)
432432
*/
433433
hashAlgorithm?: string;
434+
/**
435+
* Time in ms after which idle period cache storing should happen (only for store: 'pack' or 'idle')
436+
*/
437+
idleTimeout?: number;
434438
/**
435439
* Display log info. (debug: all access and errors with stack trace, verbose: all access, info: all write access, warning: only failed serialization)
436440
*/

lib/cache/FileCachePlugin.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ class FileCachePlugin {
126126
? { debug: 4, verbose: 3, info: 2, warning: 1 }[this.options.loglevel]
127127
: 0;
128128
const store = this.options.store || "pack";
129+
const idleTimeout = this.options.idleTimeout || 0;
129130

130131
const resolvedPromise = Promise.resolve();
131132

@@ -364,11 +365,19 @@ class FileCachePlugin {
364365
}
365366
}
366367
};
368+
let idleTimer = undefined;
367369
compiler.cache.hooks.beginIdle.tap("FileCachePlugin", () => {
368-
isIdle = true;
369-
resolvedPromise.then(processIdleTasks);
370+
idleTimer = setTimeout(() => {
371+
idleTimer = undefined;
372+
isIdle = true;
373+
resolvedPromise.then(processIdleTasks);
374+
}, idleTimeout);
370375
});
371376
compiler.cache.hooks.endIdle.tap("FileCachePlugin", () => {
377+
if (idleTimer) {
378+
clearTimeout(idleTimer);
379+
idleTimer = undefined;
380+
}
372381
isIdle = false;
373382
});
374383
}

schemas/WebpackOptions.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@
168168
"description": "Algorithm used for generation the hash (see node.js crypto package)",
169169
"type": "string"
170170
},
171+
"idleTimeout": {
172+
"description": "Time in ms after which idle period cache storing should happen (only for store: 'pack' or 'idle')",
173+
"type": "number",
174+
"minimum": 0
175+
},
171176
"loglevel": {
172177
"description": "Display log info. (debug: all access and errors with stack trace, verbose: all access, info: all write access, warning: only failed serialization)",
173178
"enum": ["debug", "verbose", "info", "warning"]

0 commit comments

Comments
 (0)