remarks export class WeakCache < T extends object , U > { private readonly cacheItems = new WeakMap < T , U > ( ) ; 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 ) ; } removeByKey ( key ) { this . cacheItems . delete ( key ) ; } }