remarks export class KeyValueCache < T , U > { private readonly cacheItems = new Map < T , U > ( ) ; getSize ( ) { return this . cacheItems . size ; } getValues ( ) { return this . cacheItems . values ( ) ; } getValuesAsArray ( ) { return Array . from ( this . getValues ( ) ) ; } getKeys ( ) { return this . cacheItems . keys ( ) ; } getEntries ( ) { return this . cacheItems . entries ( ) ; } getOrCreate < TCreate extends U = U > ( key , createFunc ) { let item = this . get ( key ) as TCreate ; if ( item == null ) { item = createFunc ( ) ; this . set ( key , item ) ; } return item ; } has ( key ) { return this . cacheItems . has ( key ) ; } get ( key ) { return this . cacheItems . get ( key ) ; } set ( key , value ) { this . cacheItems . set ( key , value ) ; } replaceKey ( key , newKey ) { if ( ! this . cacheItems . has ( key ) ) throw new Error ( "Key not found." ) ; const value = this . cacheItems . get ( key ) ! ; this . cacheItems . delete ( key ) ; this . cacheItems . set ( newKey , value ) ; } removeByKey ( key ) { this . cacheItems . delete ( key ) ; } clear ( ) { this . cacheItems . clear ( ) ; } }