UNPKG

@nanggo/social-preview

Version:

Generate beautiful social media preview images from any URL

61 lines (60 loc) 1.77 kB
/** * LRU Cache implementation with TTL support * Used for caching metadata extraction results * * @example * ```typescript * import { metadataCache, stopCacheCleanup, startCacheCleanup } from './cache'; * * // For graceful server shutdown * process.on('SIGTERM', () => { * stopCacheCleanup(); * // ... other cleanup * }); * * // For testing environments * afterAll(() => { * stopCacheCleanup(); * }); * * // Custom cleanup interval (5 minutes) * stopCacheCleanup(); * startCacheCleanup(5 * 60 * 1000); * ``` */ export declare class LRUCache<T> { private cache; private maxSize; private defaultTTL; constructor(maxSize?: number, defaultTTL?: number); set(key: string, value: T, ttl?: number): void; get(key: string): T | undefined; has(key: string): boolean; delete(key: string): boolean; clear(): void; size(): number; cleanup(): number; getStats(): { size: number; maxSize: number; defaultTTL: number; }; } import { ExtractedMetadata, GeneratedPreview } from '../types'; export declare const metadataCache: LRUCache<ExtractedMetadata>; export declare const previewCache: LRUCache<GeneratedPreview>; /** * Starts automatic cache cleanup if not already running. * @param intervalMs - Cleanup interval in milliseconds (default: 10 minutes) */ export declare function startCacheCleanup(intervalMs?: number): void; /** * Stops the automatic cache cleanup interval. * Useful for graceful shutdown in applications and testing environments. */ export declare function stopCacheCleanup(): void; /** * Checks if automatic cache cleanup is currently running. * @returns true if cleanup interval is active */ export declare function isCacheCleanupRunning(): boolean;