Skip to content

Commit

Permalink
fix(@ngtools/webpack): remove redundant inline style cache
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
clydin authored and alan-agius4 committed Jun 2, 2021
1 parent 7bba446 commit a9c3a35
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions packages/ngtools/webpack/src/resource_loader.ts
Expand Up @@ -24,7 +24,6 @@ export class WebpackResourceLoader {
private _reverseDependencies = new Map<string, Set<string>>();

private fileCache?: Map<string, CompilationOutput>;
private inlineCache?: Map<string, CompilationOutput>;
private assetCache?: Map<string, Asset>;

private modifiedResources = new Set<string>();
Expand All @@ -33,7 +32,6 @@ export class WebpackResourceLoader {
constructor(shouldCache: boolean) {
if (shouldCache) {
this.fileCache = new Map();
this.inlineCache = new Map();
this.assetCache = new Map();
}
}
Expand Down Expand Up @@ -99,15 +97,16 @@ export class WebpackResourceLoader {
data?: string,
mimeType?: string,
resourceType?: 'style' | 'template',
hash?: string,
containingFile?: string,
): Promise<CompilationOutput> {
if (!this._parentCompilation) {
throw new Error('WebpackResourceLoader cannot be used without parentCompilation');
}

// 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.`);
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit a9c3a35

Please sign in to comment.