This commit is contained in:
2026-03-31 16:38:22 -07:00
commit 38940436a7
2112 changed files with 376929 additions and 0 deletions

54
node_modules/@11ty/eleventy-img/src/disk-cache.js generated vendored Normal file
View File

@ -0,0 +1,54 @@
// const debug = require("debug")("Eleventy:Image");
class DiskCache {
#existsCache;
constructor() {
this.hitCounter = 0;
this.missCounter = 0;
this.inputs = new Map();
}
setExistsCache(existsCache) {
this.#existsCache = existsCache;
}
resetCount() {
this.hitCounter = 0;
this.missCounter = 0;
}
getCount() {
return [this.hitCounter, this.missCounter];
}
isCached(targetFile, sourceInput, incrementCounts = true) {
if(!this.#existsCache) {
throw new Error("Missing `#existsCache`");
}
// Disk cache runs once per output file, so we only increment counts once per input
if(this.inputs.has(sourceInput)) {
incrementCounts = false;
}
this.inputs.set(sourceInput, true);
if(this.#existsCache?.exists(targetFile)) {
if(incrementCounts) {
this.hitCounter++;
}
// debug("Images re-used (via disk cache): %o", this.hitCounter);
return true;
}
if(incrementCounts) {
this.missCounter++;
}
return false;
}
}
module.exports = DiskCache;