Skip to content

Commit 053c31f

Browse files
committed
Allow overriding functions of LRUDiskCache by subclasses
1 parent 6513c3b commit 053c31f

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/caches/LRUDiskCache.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,17 @@ export class LRUDiskCache<V> implements CacheLayer<string, V>{
4545
* Subclasses that need to store more than just the time of death should
4646
* override this.
4747
*/
48-
protected buildLruData(timeOfDeath: number, localCacheOptions?: LocalCacheOptions): LRUData {
48+
protected buildLRUData(timeOfDeath: number, localCacheOptions?: LocalCacheOptions): LRUData {
4949
return { timeOfDeath }
5050
}
5151

52-
public has = (key: string): boolean => this.lruStorage.has(key)
52+
protected getLRU() {
53+
return this.lruStorage
54+
}
55+
56+
public has (key: string): boolean {
57+
return this.lruStorage.has(key)
58+
}
5359

5460
public getStats = (name='disk-lru-cache'): LRUStats => {
5561
const stats = {
@@ -68,7 +74,7 @@ export class LRUDiskCache<V> implements CacheLayer<string, V>{
6874
return stats
6975
}
7076

71-
public get = async (key: string): Promise<V | void> => {
77+
public async get (key: string): Promise<V | void> {
7278
const lruData = this.lruStorage.get(key)
7379
this.total += 1
7480
if (lruData === undefined) {
@@ -105,9 +111,9 @@ export class LRUDiskCache<V> implements CacheLayer<string, V>{
105111
return data
106112
}
107113

108-
public set = async (key: string, value: V, maxAge?: number, localCacheOptions?: LocalCacheOptions): Promise<boolean> => {
114+
public async set (key: string, value: V, maxAge?: number, localCacheOptions?: LocalCacheOptions): Promise<boolean> {
109115
let timeOfDeath = maxAge ? maxAge + Date.now() : NaN
110-
const lruData = this.buildLruData(timeOfDeath, localCacheOptions)
116+
const lruData = this.buildLRUData(timeOfDeath, localCacheOptions)
111117
this.lruStorage.set(key, lruData, maxAge ? maxAge : undefined)
112118

113119
if (this.keyToBeDeleted && this.keyToBeDeleted !== key) {

0 commit comments

Comments
 (0)