MCPcopy
hub / github.com/webpack/webpack / apply

Method apply

lib/cache/MemoryCachePlugin.js:20–54  ·  view source on GitHub ↗

* Applies the plugin by registering its hooks on the compiler. * @param {Compiler} compiler the compiler instance * @returns {void}

(compiler)

Source from the content-addressed store, hash-verified

18 * @returns {void}
19 */
20 apply(compiler) {
21 /** @type {Map<string, { etag: Etag | null, data: Data } | null>} */
22 const cache = new Map();
23 compiler.cache.hooks.store.tap(
24 { name: "MemoryCachePlugin", stage: Cache.STAGE_MEMORY },
25 (identifier, etag, data) => {
26 cache.set(identifier, { etag, data });
27 }
28 );
29 compiler.cache.hooks.get.tap(
30 { name: "MemoryCachePlugin", stage: Cache.STAGE_MEMORY },
31 (identifier, etag, gotHandlers) => {
32 const cacheEntry = cache.get(identifier);
33 if (cacheEntry === null) {
34 return null;
35 } else if (cacheEntry !== undefined) {
36 return cacheEntry.etag === etag ? cacheEntry.data : null;
37 }
38 gotHandlers.push((result, callback) => {
39 if (result === undefined) {
40 cache.set(identifier, null);
41 } else {
42 cache.set(identifier, { etag, data: result });
43 }
44 return callback();
45 });
46 }
47 );
48 compiler.cache.hooks.shutdown.tap(
49 { name: "MemoryCachePlugin", stage: Cache.STAGE_MEMORY },
50 () => {
51 cache.clear();
52 }
53 );
54 }
55}
56
57module.exports = MemoryCachePlugin;

Callers

nothing calls this directly

Calls 6

tapMethod · 0.80
callbackFunction · 0.50
setMethod · 0.45
getMethod · 0.45
pushMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected