/** * CacheManager - TanStack Query-inspired cache management * * Provides unified cache invalidation and optimistic update patterns. */ import type { EventEmitter } from '../base/event-emitter.js'; import type { HandlerChain } from '../handlers/handler-chain.js'; /** * Options for cache invalidation (like TanStack's invalidateQueries) */ export interface InvalidateOptions { /** Invalidate by namespace */ namespace?: string; /** Invalidate by locale */ locale?: string; /** Invalidate specific key */ key?: string; /** Custom predicate filter */ predicate?: (key: string) => boolean; /** Whether to refetch after invalidation (default: true) */ refetch?: boolean; } /** * Cached translation entry */ export interface CacheEntry { value: string; styles?: Record; } /** * Cache event payloads */ export interface CacheEventPayloads { 'cache:invalidate': { filter: InvalidateOptions; keysCleared: number; refetch: boolean; }; 'cache:set': { key: string; value: string; styles?: Record; optimistic: boolean; }; 'cache:rollback': { key: string; reason: string; }; } /** * CacheManager - Unified cache API inspired by TanStack Query * * @example * ```typescript * // Invalidate by namespace * await i18n.cache.invalidate({ namespace: 'app' }); * * // Optimistic update * const previous = i18n.cache.get('en:app:welcome'); * i18n.cache.set('en:app:welcome', 'New value'); * // ... if error, rollback: * i18n.cache.set('en:app:welcome', previous.value); * ``` */ export declare class CacheManager { private handlerChain; private bus; private currentLocale; private loadNamespaces; constructor(handlerChain: HandlerChain, bus: EventEmitter, getCurrentLocale: () => string, loadNamespaces: (locale: string, namespaces: string[]) => Promise); /** * Get a cached translation entry * * @param key - Full cache key (e.g., 'en:app:welcome') * @returns Cache entry with value and styles, or null if not found */ get(key: string): CacheEntry | null; /** * Set a cache entry (for optimistic updates) * * @param key - Full cache key (e.g., 'en:app:welcome') * @param value - Translation value * @param styles - Optional styles for indexed tags */ set(key: string, value: string, styles?: Record): void; /** * Check if a key exists in cache * * @param key - Full cache key (e.g., 'en:app:welcome') * @returns true if key is cached */ has(key: string): boolean; /** * Invalidate cache entries and optionally refetch * * Like TanStack Query's invalidateQueries, this clears matching cache entries * and triggers background refetch by default. * * @param options - Filter options for invalidation * * @example * ```typescript * // Invalidate all * await cache.invalidate(); * * // Invalidate by namespace * await cache.invalidate({ namespace: 'app' }); * * // Invalidate by locale * await cache.invalidate({ locale: 'es' }); * * // Invalidate specific key * await cache.invalidate({ key: 'en:app:welcome' }); * * // Invalidate with predicate * await cache.invalidate({ predicate: (k) => k.includes('common:') }); * * // Invalidate without refetch * await cache.invalidate({ namespace: 'app', refetch: false }); * ``` */ invalidate(options?: InvalidateOptions): Promise; /** * Count keys that would be cleared (for event reporting) */ private countClearedKeys; /** * Refetch data after invalidation */ private refetchAfterInvalidate; } //# sourceMappingURL=CacheManager.d.ts.map