UNPKG

crewai-ts

Version:

TypeScript port of crewAI for agent-based workflows

91 lines 2.65 kB
/** * OptimizedMemoryCache implementation * Uses WeakRef for large memory items to allow garbage collection * and minimize memory pressure while maintaining performance */ /** * Options for configuring OptimizedMemoryCache behavior */ export interface OptimizedMemoryCacheOptions { /** * Size threshold (in approximate bytes) for storing items as weak references * Items larger than this threshold will be stored as weak references * @default 50000 (~50KB) */ largeObjectThreshold?: number; /** * Whether to track memory usage statistics * @default true */ trackStats?: boolean; } /** * Memory cache item with metadata */ export interface MemoryCacheItem<T> { value: T; createdAt: number; lastAccessedAt: number; size: number; isWeak: boolean; } /** * OptimizedMemoryCache class * Provides efficient memory caching with weak references for large objects * to allow garbage collection when memory pressure is high */ export declare class OptimizedMemoryCache<T = any> { private strongCache; private weakCache; private registry; private largeObjectThreshold; private trackStats; private stats; constructor(options?: OptimizedMemoryCacheOptions); /** * Store a value in the cache * Large objects are stored as weak references to allow garbage collection */ set(key: string, value: T): void; /** * Retrieve a value from the cache, handling both strong and weak references */ get(key: string): T | undefined; /** * Remove an item from the cache */ delete(key: string): boolean; /** * Check if a key exists in the cache * Note: This doesn't guarantee the item still exists if it's a weak reference */ has(key: string): boolean; /** * Clear all items from the cache */ clear(): void; /** * Get the number of items in the cache * Note: This may include weak references to objects that have been garbage collected */ get size(): number; /** * Get memory usage statistics */ getStats(): typeof this.stats; /** * Execute a function for each item in the strong cache * Skips weak references as they may have been garbage collected */ forEach(callback: (value: T, key: string) => void): void; /** * Get all keys in the cache (both strong and weak) */ keys(): string[]; /** * Get all values from the strong cache * (Excludes weak references as they may have been garbage collected) */ values(): T[]; } //# sourceMappingURL=OptimizedMemoryCache.d.ts.map