Skip to content

Commit a9c3a35

Browse files
clydinalan-agius4
authored andcommitted
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 f9657bc)
1 parent 7bba446 commit a9c3a35

File tree

1 file changed

+10
-21
lines changed

1 file changed

+10
-21
lines changed

packages/ngtools/webpack/src/resource_loader.ts

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export class WebpackResourceLoader {
2424
private _reverseDependencies = new Map<string, Set<string>>();
2525

2626
private fileCache?: Map<string, CompilationOutput>;
27-
private inlineCache?: Map<string, CompilationOutput>;
2827
private assetCache?: Map<string, Asset>;
2928

3029
private modifiedResources = new Set<string>();
@@ -33,7 +32,6 @@ export class WebpackResourceLoader {
3332
constructor(shouldCache: boolean) {
3433
if (shouldCache) {
3534
this.fileCache = new Map();
36-
this.inlineCache = new Map();
3735
this.assetCache = new Map();
3836
}
3937
}
@@ -99,15 +97,16 @@ export class WebpackResourceLoader {
9997
data?: string,
10098
mimeType?: string,
10199
resourceType?: 'style' | 'template',
102-
hash?: string,
103100
containingFile?: string,
104101
): Promise<CompilationOutput> {
105102
if (!this._parentCompilation) {
106103
throw new Error('WebpackResourceLoader cannot be used without parentCompilation');
107104
}
108105

109106
// Create a special URL for reading the resource from memory
110-
const entry = data ? `angular-resource:${resourceType},${hash}` : filePath;
107+
const entry = data
108+
? `angular-resource:${resourceType},${createHash('md5').update(data).digest('hex')}`
109+
: filePath;
111110
if (!entry) {
112111
throw new Error(`"filePath" or "data" must be specified.`);
113112
}
@@ -322,23 +321,13 @@ export class WebpackResourceLoader {
322321
return '';
323322
}
324323

325-
const cacheKey = createHash('md5').update(data).digest('hex');
326-
let compilationResult = this.inlineCache?.get(cacheKey);
327-
328-
if (compilationResult === undefined) {
329-
compilationResult = await this._compile(
330-
undefined,
331-
data,
332-
mimeType,
333-
resourceType,
334-
cacheKey,
335-
containingFile,
336-
);
337-
338-
if (this.inlineCache && compilationResult.success) {
339-
this.inlineCache.set(cacheKey, compilationResult);
340-
}
341-
}
324+
const compilationResult = await this._compile(
325+
undefined,
326+
data,
327+
mimeType,
328+
resourceType,
329+
containingFile,
330+
);
342331

343332
return compilationResult.content;
344333
}

0 commit comments

Comments
 (0)