Skip to content

Commit 4ed5622

Browse files
committed
add direct memory cache
1 parent 2688b5b commit 4ed5622

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lib/cache/FileCachePlugin.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ class FileCachePlugin {
102102
*/
103103
constructor(options) {
104104
this.options = options;
105+
this.directMemoryCache = new Map();
105106
}
106107

107108
static purgeMemoryCache() {
@@ -179,6 +180,7 @@ class FileCachePlugin {
179180
};
180181
const relativeFilename = toHash(identifier) + ".data";
181182
const filename = path.join(cacheDirectory, relativeFilename);
183+
this.directMemoryCache.set(identifier, entry);
182184
memoryCache.set(filename, entry);
183185
const promiseFactory =
184186
store === "pack"
@@ -221,6 +223,16 @@ class FileCachePlugin {
221223
compiler.cache.hooks.get.tapPromise(
222224
"FileCachePlugin",
223225
(identifier, etag) => {
226+
const directMemory = this.directMemoryCache.get(identifier);
227+
if (directMemory !== undefined) {
228+
return Promise.resolve(
229+
directMemory.etag !== etag
230+
? undefined
231+
: typeof directMemory.data === "function"
232+
? directMemory.data()
233+
: directMemory.data
234+
);
235+
}
224236
const relativeFilename = toHash(identifier) + ".data";
225237
const filename = path.join(cacheDirectory, relativeFilename);
226238
const logMessage = store === "pack" ? "pack" : filename;
@@ -243,6 +255,7 @@ class FileCachePlugin {
243255
if (cacheEntry === undefined) return;
244256
if (typeof cacheEntry.data === "function")
245257
cacheEntry.data = memorize(cacheEntry.data);
258+
this.directMemoryCache.set(identifier, cacheEntry);
246259
memoryCache.set(filename, cacheEntry);
247260
if (cacheEntry === undefined) return;
248261
if (cacheEntry.identifier !== identifier) {

0 commit comments

Comments
 (0)