Merge pull request #11926 from Snuffleupagus/GlobalImageCache-clear-onlyData

Allow `GlobalImageCache.clear` to, optionally, only remove the actual data (PR 11912 follow-up)
This commit is contained in:
Tim van der Meij 2020-05-23 12:21:38 +02:00 committed by GitHub
commit cd6d089489
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 9 deletions

View File

@ -844,8 +844,10 @@ class PDFDocument {
return this.catalog.fontFallback(id, handler);
}
async cleanup() {
return this.catalog ? this.catalog.cleanup() : clearPrimitiveCaches();
async cleanup(manuallyTriggered = false) {
return this.catalog
? this.catalog.cleanup(manuallyTriggered)
: clearPrimitiveCaches();
}
}

View File

@ -199,8 +199,10 @@ class GlobalImageCache {
this._imageCache.put(ref, data);
}
clear() {
this._refCache.clear();
clear(onlyData = false) {
if (!onlyData) {
this._refCache.clear();
}
this._imageCache.clear();
}
}

View File

@ -716,9 +716,9 @@ class Catalog {
});
}
cleanup() {
cleanup(manuallyTriggered = false) {
clearPrimitiveCaches();
this.globalImageCache.clear();
this.globalImageCache.clear(/* onlyData = */ manuallyTriggered);
this.pageKidsCountCache.clear();
const promises = [];

View File

@ -76,8 +76,8 @@ class BasePdfManager {
return this.pdfDocument.fontFallback(id, handler);
}
cleanup() {
return this.pdfDocument.cleanup();
cleanup(manuallyTriggered = false) {
return this.pdfDocument.cleanup(manuallyTriggered);
}
async ensure(obj, prop, args) {

View File

@ -625,7 +625,7 @@ var WorkerMessageHandler = {
});
handler.on("Cleanup", function wphCleanup(data) {
return pdfManager.cleanup();
return pdfManager.cleanup(/* manuallyTriggered = */ true);
});
handler.on("Terminate", function wphTerminate(data) {