@sonatel-os/juf
Version:
It's an helpful Javascript Utility Framework to ease application development in SONATEL context.
54 lines (53 loc) • 1.83 kB
TypeScript
/**
* Singleton instance of Cache with a default TTL of 240 seconds.
* Provides a reusable cache system throughout the application.
*
* @type {Cache}
*/
export const CachingSystem: Cache;
export default Cache;
/**
* @class Cache
* @classdesc Handles caching of data with expiration using NodeCache.
* Provides methods to store and retrieve cached data, with error handling for reliable cache management.
*
* @example
* // Create a cache instance with a TTL of 300 seconds
* const myCache = new Cache(300);
*
* // Store a value in the cache
* myCache.store('myKey', { data: 'value' });
*
* // Retrieve a value from the cache
* const cachedData = myCache.retrieve('myKey');
* console.log(cachedData);
*/
declare class Cache {
/**
* Creates an instance of Cache.
* @param {number} ttlSeconds - Time-to-live (TTL) in seconds for cached items.
*/
constructor(ttlSeconds: number);
/**
* @method store
* @memberof CacheUtil
* @description Stores a value in the cache with a specified key.
* If the cache fails to store the value, an error is logged.
*
* @param {string} key - The key under which the value is stored.
* @param {any} value - The value to be stored. Must be serializable to JSON.
* @returns {boolean} Returns true if the value is successfully stored, otherwise false.
*/
store(key: string, value: any): boolean;
/**
* @method retrieve
* @memberof CacheUtil
* @description Retrieves a value from the cache by its key.
* If the value is not found or an error occurs, null is returned.
*
* @param {string} key - The key to retrieve the value.
* @returns {object|null} Returns the parsed cached value if found, otherwise null.
*/
retrieve(key: string): object | null;
#private;
}