Implement startup cleanup for cache retrieval in EJS_Cache

This commit is contained in:
Michael Green 2025-11-20 16:55:53 +11:00
parent e74fb401c2
commit cbb7228a78

View File

@ -35,6 +35,11 @@ class EJS_Cache {
}
}
/**
* Indicates whether the startup cleanup has been completed.
*/
#startupCleanupCompleted = false;
/**
* Generates a cache key for the given data array.
* @param {Uint8Array} dataArray
@ -55,6 +60,12 @@ class EJS_Cache {
async get(key, metadataOnly = false) {
if (!this.enabled) return null;
// clean up cache on first get if not already done
if (!this.#startupCleanupCompleted) {
await this.cleanup();
this.#startupCleanupCompleted = true;
}
const item = await this.storage.get(key);
// if the item exists, update its lastAccessed time and return cache item
if (item) {