crewai-ts
Version:
TypeScript port of crewAI for agent-based workflows
90 lines • 2.6 kB
TypeScript
/**
* Cache Handler
* Optimized caching system for agent responses with efficient memory usage
*/
/**
* Cache options for configuring the CacheHandler
*/
export interface CacheOptions {
/** Maximum number of items to store in the cache */
maxSize?: number;
/** Time in milliseconds after which cache entries expire */
ttl?: number;
/** Whether to enable cache persistence */
persistence?: boolean;
/** Directory to store persistent cache (if enabled) */
persistenceDir?: string;
}
/**
* Efficient cache handler optimized for agent responses
* Implements LRU caching strategy with optional persistence
*/
export declare class CacheHandler {
private cache;
private readonly maxSize;
private readonly ttl;
private readonly persistence;
private readonly persistenceDir?;
/**
* Create a new CacheHandler
* @param options Cache configuration options
*/
constructor(options?: CacheOptions);
/**
* Generate a cache key from inputs
* @param keyParts Components to generate the key from
* @returns A hash-based cache key
*/
generateKey(...keyParts: any[]): string;
/**
* Get a value from the cache
* @param key Cache key
* @returns The cached value or undefined if not found
*/
get<T>(key: string): T | undefined;
/**
* Set a value in the cache
* @param key Cache key
* @param value Value to cache
*/
set<T>(key: string, value: T): void;
/**
* Check if a key exists in the cache and is not expired
* @param key Cache key
* @returns True if the key exists and is not expired
*/
has(key: string): boolean;
/**
* Delete a key from the cache
* @param key Cache key
* @returns True if the key was deleted, false otherwise
*/
delete(key: string): boolean;
/**
* Clear the entire cache
*/
clear(): void;
/**
* Get a value from the cache or compute it if not found
* @param key Cache key
* @param producer Function to produce the value if not in cache
* @returns The cached or computed value
*/
getOrCompute<T>(key: string, producer: () => Promise<T>): Promise<T>;
/**
* Remove the least recently used item from the cache
* @private
*/
private evictLRU;
/**
* Save the cache to disk if persistence is enabled
* @private
*/
private saveToDisk;
/**
* Load the cache from disk if persistence is enabled
* @private
*/
private loadFromDisk;
}
//# sourceMappingURL=CacheHandler.d.ts.map