const DEFAULT_CACHE_TTL_MS = 1000 * 60 * 5 ; type CacheEntry < R > = { expiry : number ; value : R ; } ; type FunctionType < R > = ( key : string , ... args : any [ ] ) => Promise < R > ; type ArgumentsType < R , T extends FunctionType < R > > = T extends ( key : string , ... args : infer A ) => Promise < R > ? A : never ; export class SolariumCache < R , F extends FunctionType < R > > { private store : Record < string , CacheEntry < R > > ; constructor ( private wrappedFunction , private ttl = DEFAULT_CACHE_TTL_MS ) { this . store = { } ; } getCached ( key ) { return this . store [ key ] ?. value ; } set ( key , value ) { this . store [ key ] = { expiry : Date . now ( ) + this . ttl , value } ; } evictCache ( key ) { delete this . store [ key ] ; } async load ( key , skipCache , ... args ) { const entry = this . store [ key ] ; if ( ! skipCache && entry && entry . expiry > Date . now ( ) ) return entry . value ; const loadedValue = await this . wrappedFunction ( key , ... args ) ; if ( loadedValue ) this . set ( key , loadedValue ) ; return loadedValue ; } }