From a9c3a35fc2777926689928b68d730cbbcddfe200 Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Thu, 27 May 2021 15:32:24 -0400 Subject: [PATCH] fix(@ngtools/webpack): remove redundant inline style cache The size of the cache could grow quite large over long active development periods. Webpack 5 memory caching will also allow for caching of the data. (cherry picked from commit f9657bc919a223e449d2dd559347eed85b1f8919) --- .../ngtools/webpack/src/resource_loader.ts | 31 ++++++------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/packages/ngtools/webpack/src/resource_loader.ts b/packages/ngtools/webpack/src/resource_loader.ts index 07018f2df4a1..6868e103afda 100644 --- a/packages/ngtools/webpack/src/resource_loader.ts +++ b/packages/ngtools/webpack/src/resource_loader.ts @@ -24,7 +24,6 @@ export class WebpackResourceLoader { private _reverseDependencies = new Map>(); private fileCache?: Map; - private inlineCache?: Map; private assetCache?: Map; private modifiedResources = new Set(); @@ -33,7 +32,6 @@ export class WebpackResourceLoader { constructor(shouldCache: boolean) { if (shouldCache) { this.fileCache = new Map(); - this.inlineCache = new Map(); this.assetCache = new Map(); } } @@ -99,7 +97,6 @@ export class WebpackResourceLoader { data?: string, mimeType?: string, resourceType?: 'style' | 'template', - hash?: string, containingFile?: string, ): Promise { if (!this._parentCompilation) { @@ -107,7 +104,9 @@ export class WebpackResourceLoader { } // Create a special URL for reading the resource from memory - const entry = data ? `angular-resource:${resourceType},${hash}` : filePath; + const entry = data + ? `angular-resource:${resourceType},${createHash('md5').update(data).digest('hex')}` + : filePath; if (!entry) { throw new Error(`"filePath" or "data" must be specified.`); } @@ -322,23 +321,13 @@ export class WebpackResourceLoader { return ''; } - const cacheKey = createHash('md5').update(data).digest('hex'); - let compilationResult = this.inlineCache?.get(cacheKey); - - if (compilationResult === undefined) { - compilationResult = await this._compile( - undefined, - data, - mimeType, - resourceType, - cacheKey, - containingFile, - ); - - if (this.inlineCache && compilationResult.success) { - this.inlineCache.set(cacheKey, compilationResult); - } - } + const compilationResult = await this._compile( + undefined, + data, + mimeType, + resourceType, + containingFile, + ); return compilationResult.content; }