/** * Intelligent cache invalidation strategies for WordPress MCP Server * Implements event-based and pattern-based invalidation */ import { HttpCacheWrapper } from "./HttpCacheWrapper.js"; export interface InvalidationRule { trigger: string; patterns: string[]; immediate?: boolean; cascade?: boolean; } export interface InvalidationEvent { type: "create" | "update" | "delete"; resource: string; id?: number | undefined; siteId: string; timestamp: number; data?: unknown; } /** * Cache invalidation manager that handles intelligent cache clearing */ export declare class CacheInvalidation { private httpCache; invalidationRules: Map; eventQueue: InvalidationEvent[]; processing: boolean; private drainingPromise; private logger; constructor(httpCache: HttpCacheWrapper); /** * Register invalidation rule */ registerRule(resource: string, rule: InvalidationRule): void; /** * Trigger invalidation event. Resolves only once the event has actually been * processed (cache entries genuinely cleared) — callers such as * `CachedWordPressClient` depend on this for read-after-write consistency: * an immediate read after an awaited write must not see stale cached data. */ trigger(event: InvalidationEvent): Promise; /** * Invalidate cache for specific resource */ invalidateResource(resource: string, id?: number, type?: "create" | "update" | "delete"): Promise; /** * Setup default invalidation rules */ private setupDefaultRules; /** * Process invalidation event queue, draining it synchronously (fully awaited) * before returning. No caller currently needs fire-and-forget/background * invalidation — if one ever does, add a separate explicitly-named method * rather than reintroducing a hidden defer flag here. * * If a drain is already in flight (`processing === true`), join it instead of * returning immediately: an event pushed onto `eventQueue` by a concurrent * `trigger()` call is picked up by that same drain loop (it re-checks the * queue every iteration), but the caller must still await until its own * event has actually been processed — otherwise a second `trigger()` call * arriving mid-drain would resolve before its event is applied, breaking the * read-after-write guarantee for concurrent writes (caught in PR #209 review * by both Copilot and Codex). */ processQueue(): Promise; /** * Drain the event queue until empty, tolerating per-event failures so one * bad event can't block invalidation of the rest. */ private drainQueue; /** * Process single invalidation event */ processEvent(event: InvalidationEvent): Promise; /** * Apply invalidation rule to cache */ /** * Public entry used by tests - apply a rule for a specific event. * Supports pattern substitution (e.g. {id}) and basic cascading. */ applyRule(rule: InvalidationRule, event: InvalidationEvent): Promise; /** * Batch invalidate a set of events - deduplicate patterns before invalidating */ batchInvalidate(events: InvalidationEvent[]): Promise; /** * Match a key against a pattern. Supports wildcard '*' and regex-style patterns. */ matchPattern(key: string, pattern: string): boolean; /** * Get invalidation statistics */ getStats(): { queueSize: number; rulesCount: number; processing: boolean; }; /** * Clear all invalidation rules */ clearRules(): void; /** * Get all registered rules */ getRules(): Record; } /** * Cache invalidation patterns for common WordPress operations */ export declare class WordPressCachePatterns { /** * Invalidate all content-related caches */ static invalidateContent(cache: HttpCacheWrapper): number; /** * Invalidate all taxonomy-related caches */ static invalidateTaxonomies(cache: HttpCacheWrapper): number; /** * Invalidate all user-related caches */ static invalidateUsers(cache: HttpCacheWrapper): number; /** * Invalidate search-related caches */ static invalidateSearch(cache: HttpCacheWrapper): number; /** * Invalidate all caches (nuclear option) */ static invalidateAll(cache: HttpCacheWrapper): number; } /** * Cache warming strategies for common WordPress data */ export declare class CacheWarmer { private httpCache; private logger; constructor(httpCache: HttpCacheWrapper); /** * Warm cache with essential WordPress data */ warmEssentials(): Promise; /** * Warm cache with taxonomy data */ warmTaxonomies(): Promise; /** * Warm cache with user data */ warmUsers(): Promise; } //# sourceMappingURL=CacheInvalidation.d.ts.map