diff --git a/src/caches/LRUDiskCache.ts b/src/caches/LRUDiskCache.ts index 2dd57b0c..c5587306 100644 --- a/src/caches/LRUDiskCache.ts +++ b/src/caches/LRUDiskCache.ts @@ -11,10 +11,10 @@ export type LRUData = Record & { timeOfDeath: number } export class LRUDiskCache implements CacheLayer{ - private lock: ReadWriteLock protected disposed: number protected hits = 0 protected total = 0 + private lock: ReadWriteLock private lruStorage: LRU private keyToBeDeleted: string @@ -40,19 +40,6 @@ export class LRUDiskCache implements CacheLayer{ } - /** - * Builds the data object that will be stored at the LRU memory storage. - * Subclasses that need to store more than just the time of death should - * override this. - */ - protected buildLRUData(timeOfDeath: number, localCacheOptions?: LocalCacheOptions): LRUData { - return { timeOfDeath } - } - - protected getLRU() { - return this.lruStorage - } - public has (key: string): boolean { return this.lruStorage.has(key) } @@ -112,7 +99,7 @@ export class LRUDiskCache implements CacheLayer{ } public async set (key: string, value: V, maxAge?: number, localCacheOptions?: LocalCacheOptions): Promise { - let timeOfDeath = maxAge ? maxAge + Date.now() : NaN + const timeOfDeath = maxAge ? maxAge + Date.now() : NaN const lruData = this.buildLRUData(timeOfDeath, localCacheOptions) this.lruStorage.set(key, lruData, maxAge ? maxAge : undefined) @@ -137,6 +124,19 @@ export class LRUDiskCache implements CacheLayer{ return !failure } + /** + * Builds the data object that will be stored at the LRU memory storage. + * Subclasses that need to store more than just the time of death should + * override this. + */ + protected buildLRUData(timeOfDeath: number, localCacheOptions?: LocalCacheOptions): LRUData { + return { timeOfDeath } + } + + protected getLRU() { + return this.lruStorage + } + private getPathKey = (key: string): string => { return join(this.cachePath, key) }