Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
feat: improve caching
- Loading branch information
1 parent
92f53b6
commit defde64
Showing
27 changed files
with
3,751 additions
and
641 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,35 @@ | ||
export default class Cache { | ||
// eslint-disable-next-line no-unused-vars | ||
constructor(compilation, ignored) { | ||
constructor(compilation) { | ||
this.cache = compilation.getCache('TerserWebpackPlugin'); | ||
} | ||
|
||
// eslint-disable-next-line class-methods-use-this | ||
isEnabled() { | ||
return true; | ||
} | ||
|
||
async get(task) { | ||
// eslint-disable-next-line no-param-reassign | ||
task.cacheIdent = task.cacheIdent || `${task.name}`; | ||
async get(cacheData) { | ||
// eslint-disable-next-line no-param-reassign | ||
task.cacheETag = | ||
task.cacheETag || this.cache.getLazyHashedEtag(task.assetSource); | ||
cacheData.eTag = | ||
cacheData.eTag || Array.isArray(cacheData.inputSource) | ||
? cacheData.inputSource | ||
.map((item) => this.cache.getLazyHashedEtag(item)) | ||
.reduce((previousValue, currentValue) => | ||
this.cache.mergeEtags(previousValue, currentValue) | ||
) | ||
: this.cache.getLazyHashedEtag(cacheData.inputSource); | ||
|
||
return this.cache.getPromise(task.cacheIdent, task.cacheETag); | ||
return this.cache.getPromise(cacheData.name, cacheData.eTag); | ||
} | ||
|
||
async store(task, data) { | ||
return this.cache.storePromise(task.cacheIdent, task.cacheETag, data); | ||
async store(cacheData) { | ||
let data; | ||
|
||
if (cacheData.target === 'comments') { | ||
data = cacheData.output; | ||
} else { | ||
data = { | ||
source: cacheData.source, | ||
extractedCommentsSource: cacheData.extractedCommentsSource, | ||
commentsFilename: cacheData.commentsFilename, | ||
}; | ||
} | ||
|
||
return this.cache.storePromise(cacheData.name, cacheData.eTag, data); | ||
} | ||
} |
Oops, something went wrong.