Skip to content

Commit db74635

Browse files
committed
Check whether cache entry has contents as part of validity (cache files may have been purged)
1 parent 9eb6a9a commit db74635

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/AssetCache.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ const { DateCompare } = require("@11ty/eleventy-utils");
55

66
const FileCache = require("./FileCache.js");
77
const Sources = require("./Sources.js");
8-
const DirectoryManager = require("./DirectoryManager.js");
98

109
const debugUtil = require("debug");
1110
const debug = debugUtil("Eleventy:Fetch");
12-
const debugAssets = debugUtil("Eleventy:Assets");
1311

1412
class AssetCache {
1513
#source;
@@ -19,7 +17,6 @@ class AssetCache {
1917
#cacheDirectory;
2018
#cacheLocationDirty = false;
2119
#directoryManager;
22-
#rawContents = {};
2320

2421
constructor(source, cacheDirectory, options = {}) {
2522
if(!Sources.isValidSource(source)) {
@@ -227,12 +224,15 @@ class AssetCache {
227224
}
228225

229226
isCacheValid(duration = this.duration) {
230-
if (!this.cachedObject || !this.cachedObject.cachedAt) {
231-
// not cached
227+
if(!this.cachedObject || !this.cachedObject?.cachedAt) {
232228
return false;
233229
}
234230

235-
return DateCompare.isTimestampWithinDuration(this.cachedObject.cachedAt, duration);
231+
if(DateCompare.isTimestampWithinDuration(this.cachedObject?.cachedAt, duration)) {
232+
return this.cache.hasContents(); // check file system to make files haven’t been purged.
233+
}
234+
235+
return false;
236236
}
237237

238238
get cachedObject() {

src/FileCache.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,18 @@ class FileCache {
131131
return Buffer.from(rawData.contents);
132132
}
133133

134+
hasContents() {
135+
if(this.#contents) {
136+
return true;
137+
}
138+
if(!this.isSideLoaded() && this.get()?.data) {
139+
return true;
140+
} else if(this.get()?.contents) {
141+
return true;
142+
}
143+
return existsCache.exists(this.contentsPath);
144+
}
145+
134146
getContents() {
135147
if(this.#contents) {
136148
return this.#contents;

0 commit comments

Comments
 (0)