@@ -6,10 +6,12 @@ import { BasicCommandParser } from './parser';
66type CachingClient = RedisClient < any , any , any , any , any > ;
77type CmdFunc = ( ) => Promise < ReplyUnion > ;
88
9+ type EvictionPolicy = "LRU" | "FIFO"
10+
911export interface ClientSideCacheConfig {
1012 ttl ?: number ;
1113 maxEntries ?: number ;
12- lru ?: boolean ;
14+ evictPolocy ?: EvictionPolicy ;
1315}
1416
1517type CacheCreator = {
@@ -107,7 +109,7 @@ export class BasicClientSideCache extends ClientSideCacheProvider {
107109 this . #keyToCacheKeySetMap = new Map < string , Set < string > > ( ) ;
108110 this . ttl = config ?. ttl ?? 0 ;
109111 this . maxEntries = config ?. maxEntries ?? 0 ;
110- this . lru = config ?. lru ?? true ;
112+ this . lru = config ?. evictPolocy !== "FIFO"
111113 }
112114
113115 /* logic of how caching works:
@@ -165,6 +167,7 @@ export class BasicClientSideCache extends ClientSideCacheProvider {
165167 if ( cacheEntry . validate ( ) ) { // on error, have to remove promise from cache
166168 this . delete ( cacheKey ! ) ;
167169 }
170+
168171 throw err ;
169172 }
170173 }
@@ -217,25 +220,21 @@ export class BasicClientSideCache extends ClientSideCacheProvider {
217220 this . emit ( 'invalidate' , key ) ;
218221 }
219222
220- override clear ( reset = true ) {
223+ override clear ( resetStats = true ) {
221224 this . #cacheKeyToEntryMap. clear ( ) ;
222225 this . #keyToCacheKeySetMap. clear ( ) ;
223- if ( reset ) {
226+ if ( resetStats ) {
224227 this . #cacheHits = 0 ;
225228 this . #cacheMisses = 0 ;
226229 }
227230 }
228231
229- get ( cacheKey ?: string | undefined ) {
230- if ( cacheKey === undefined ) {
231- return undefined
232- }
233-
232+ get ( cacheKey : string ) {
234233 const val = this . #cacheKeyToEntryMap. get ( cacheKey ) ;
235234
236235 if ( val && ! val . validate ( ) ) {
237236 this . delete ( cacheKey ) ;
238- this . emit ( "invalidate " , cacheKey ) ;
237+ this . emit ( "cache-evict " , cacheKey ) ;
239238
240239 return undefined ;
241240 }
@@ -263,6 +262,7 @@ export class BasicClientSideCache extends ClientSideCacheProvider {
263262 set ( cacheKey : string , cacheEntry : ClientSideCacheEntry , keys : Array < RedisArgument > ) {
264263 let count = this . #cacheKeyToEntryMap. size ;
265264 const oldEntry = this . #cacheKeyToEntryMap. get ( cacheKey ) ;
265+
266266 if ( oldEntry ) {
267267 count -- ; // overwriting, so not incrementig
268268 oldEntry . invalidate ( ) ;
@@ -419,11 +419,8 @@ class PooledClientSideCacheEntryPromise extends ClientSideCacheEntryPromise {
419419
420420 override validate ( ) : boolean {
421421 let ret = super . validate ( ) ;
422- if ( this . #creator) {
423- ret = ret && this . #creator. client . isReady && this . #creator. client . socketEpoch == this . #creator. epoch
424- }
425-
426- return ret ;
422+
423+ return ret && this . #creator. client . isReady && this . #creator. client . socketEpoch == this . #creator. epoch
427424 }
428425}
429426
0 commit comments