interface CacheInterface < T > { hasKey ( key ) : boolean ; get ( key ) : T | undefined ; set ( key , item , expirationTime ? ) : void ; } interface DateInputObject { hours ? : number ; minutes ? : number ; seconds ? : number ; milliseconds ? : number ; } internal export interface CacheEntry < T > { expires ? : number ; entry : T ; } /**
 * Enumerator that selects the isolation type of destination in cache.
 */ export enum IsolationStrategy { Tenant = 'Tenant' , User = 'User' , Tenant_User = 'TenantUser' , No_Isolation = 'NoIsolation' } export interface CachingOptions { /**
     * A boolean value that indicates whether to read destinations from cache.
     */ useCache ? : boolean ; /**
     * The isolation strategy used for caching destinations. For the available options, see [[IsolationStrategy]].
     * By default, IsolationStrategy.Tenant is set.
     */ isolationStrategy ? : IsolationStrategy ; } typeparam internal export class Cache < T > implements CacheInterface < T > { /**
     * Object that stores all cached entries.
     */ private cache : Record < string , CacheEntry < T > > ; /**
     * Default validity period for each entry in cache.
     * If `undefined`, all cached entries will be valid indefinitely.
     */ private defaultValidityTime : DateInputObject | undefined ; constructor ( validityTime ? ) { this . cache = { } ; this . defaultValidityTime = validityTime ; } /**
     * Clear all cached items.
     */ clear ( ) { this . cache = { } ; } param key returns hasKey ( key ) { return this . cache . hasOwnProperty ( key ) ; } param key returns get ( key ) { return key && this . hasKey ( key ) && ! isExpired ( this . cache [ key ] ) ? this . cache [ key ] . entry : undefined ; } param key param entry param expirationTime set ( key , entry , expirationTime ? ) { if ( key ) { const expires = expirationTime ? expirationTime : inferExpirationTime ( this . defaultValidityTime ) ; this . cache [ key ] = { entry , expires } ; } } } function isExpired < T > ( item ) { if ( item . expires === undefined ) { return false ; } return item . expires < Date . now ( ) ; } function inferExpirationTime ( expirationTime ) { return expirationTime ? inferExpirationTimeFromDate ( expirationTime ) : undefined ; } function inferExpirationTimeFromDate ( expirationTime ) { const currentDate = new Date ( ) ; const milliseconds = ( expirationTime ?. hours ?? 0 ) * 60 * 60 * 1000 + ( expirationTime ?. minutes ?? 0 ) * 60 * 1000 + ( expirationTime ?. seconds ?? 0 ) * 1000 + ( expirationTime ?. milliseconds ?? 0 ) ; return currentDate . setMilliseconds ( currentDate . getMilliseconds ( ) + milliseconds ) . valueOf ( ) ; }