@sap-cloud-sdk/connectivity
Version:
SAP Cloud SDK for JavaScript connectivity
82 lines (81 loc) • 2.73 kB
TypeScript
interface CacheInterface<T> {
hasKey(key: string): boolean;
get(key: string | undefined): T | undefined;
set(key: string | undefined, item: CacheEntry<T>): void;
clear(): void;
getOrInsertComputed(key: string, computeFn: () => CacheEntry<T>): T;
}
/**
* Representation of a cached object.
*/
export interface CacheEntry<T> {
/**
* The expiration time of the cache entry in milliseconds.
*/
expires?: number;
/**
* The cache entry.
*/
entry: T;
}
/**
* Options to enable caching when fetching destinations.
*/
export interface CachingOptions {
/**
* A boolean value that indicates whether to read and write destinations from and to cache.
* This never writes destinations with authentication type "SAMLAssertion".
*/
useCache?: boolean;
}
/**
* Representation of a cache to transiently store objects locally for faster access.
* @typeParam T - Type of the cache entries.
* @internal
*/
export declare class Cache<T> implements CacheInterface<T> {
private defaultValidityTime;
private capacity;
/**
* Object that stores all cached entries.
*/
private cache;
/**
* Creates an instance of Cache.
* @param defaultValidityTime - The default validity time in milliseconds. Use 0 for unlimited cache duration.
* @param capacity - The maximum number of entries in the cache. Use Infinity for unlimited size. Items are evicted based on a least recently used (LRU) strategy.
*/
constructor(defaultValidityTime: number, capacity?: number);
/**
* Clear all cached items.
*/
clear(): void;
/**
* Specifies whether an entry with a given key is defined in cache.
* @param key - The entry's key.
* @returns A boolean value that indicates whether the entry exists in cache.
*/
hasKey(key: string): boolean;
/**
* Getter of cached entries.
* @param key - The key of the entry to retrieve.
* @returns The corresponding entry to the provided key if it is still valid, returns `undefined` otherwise.
*/
get(key: string | undefined): T | undefined;
/**
* Setter of entries in cache.
* @param key - The entry's key.
* @param item - The entry to cache.
*/
set(key: string | undefined, item: CacheEntry<T>): void;
getOrInsertComputed(key: string, computeFn: () => CacheEntry<T>): T;
private inferDefaultExpirationTime;
}
/**
* Hashes the given value to create a cache key.
* @internal
* @param value - The value to hash.
* @returns A hash of the given value using a cryptographic hash function.
*/
export declare function hashCacheKey(value: Record<string, unknown>): Promise<string>;
export {};