/** * @db4/core - Cache Invalidation * * Provides a centralized cache invalidation mechanism for db4 caches: * - Query plan cache (DoSQLEngine) * - Prepared statement cache (DoSQLGenerator) * - Compiled procedure cache (StoredProcedureCompiler) * * @packageDocumentation */ /** * Reason for cache invalidation. */ export type InvalidationReason = { type: 'schema_change'; tables: string[]; } | { type: 'table_drop'; table: string; } | { type: 'manual'; }; /** * Callback function for invalidation events. */ export type InvalidationCallback = (reason: InvalidationReason) => void; /** * Cache invalidator interface for coordinating cache invalidation * across multiple caches in the db4 system. */ export interface CacheInvalidator { /** * Trigger cache invalidation. * @param reason The reason for invalidation */ invalidate(reason: InvalidationReason): void; /** * Subscribe to invalidation events. * @param callback Function to call when invalidation occurs * @returns Unsubscribe function */ onInvalidate(callback: InvalidationCallback): () => void; } /** * Options for creating a cache invalidator. */ export interface CacheInvalidatorOptions { /** * If true, calls to invalidate() are synchronous and block until * all callbacks have been executed. Default: false (async). */ synchronous?: boolean; } /** * Create a new cache invalidator instance. * * @example * ```typescript * const invalidator = createCacheInvalidator(); * * // Subscribe to invalidation events * const unsubscribe = invalidator.onInvalidate((reason) => { * console.log('Cache invalidated:', reason); * }); * * // Trigger invalidation * invalidator.invalidate({ type: 'schema_change', tables: ['users'] }); * * // Cleanup * unsubscribe(); * ``` */ export declare function createCacheInvalidator(options?: CacheInvalidatorOptions): CacheInvalidator; /** * Check if an invalidation reason affects a specific table. * * @param reason The invalidation reason * @param table The table name to check * @returns true if the table is affected by this invalidation */ export declare function invalidationAffectsTable(reason: InvalidationReason, table: string): boolean; /** * Create an invalidation reason for a schema change. */ export declare function schemaChangeReason(tables: string[]): InvalidationReason; /** * Create an invalidation reason for a table drop. */ export declare function tableDropReason(table: string): InvalidationReason; /** * Create a manual invalidation reason. */ export declare function manualInvalidationReason(): InvalidationReason; /** * Type guard to check if a reason is a schema change. */ export declare function isSchemaChangeReason(reason: InvalidationReason): reason is { type: 'schema_change'; tables: string[]; }; /** * Type guard to check if a reason is a table drop. */ export declare function isTableDropReason(reason: InvalidationReason): reason is { type: 'table_drop'; table: string; }; /** * Type guard to check if a reason is a manual invalidation. */ export declare function isManualInvalidationReason(reason: InvalidationReason): reason is { type: 'manual'; }; //# sourceMappingURL=cache-invalidation.d.ts.map