/** * Validation result caching system for incremental validation. * * @file Provides caching capabilities for link validation results to improve performance * * @category Utils */ import type { BrokenLink } from "../types/config.js"; /** * The per-file validation outcome stored in the cache. * * @category Utils */ export interface ValidationResult { /** Broken links found in the file */ brokenLinks: BrokenLink[]; /** Total number of links checked in the file */ totalLinks: number; /** Whether any of the checked links were external, which the TTL gate re-checks over time */ hasExternalLinks: boolean; } /** * Cached validation result for a file. * * @category Utils */ export interface CachedValidationResult { /** File path that was validated */ filePath: string; /** Hash of file content when validated */ contentHash: string; /** Git commit hash when validated */ gitCommit?: string; /** Timestamp when validation was performed */ timestamp: number; /** TTL for external link checks (milliseconds) */ externalLinksTtl: number; /** Validation result */ result: ValidationResult; /** Markmv version used for validation */ version: string; /** Configuration hash used for validation */ configHash: string; } /** * Cache metadata and statistics. * * @category Utils */ export interface CacheMetadata { /** Total number of cached files */ totalFiles: number; /** Total number of cached links */ totalLinks: number; /** Cache hit rate percentage */ hitRate: number; /** Size of cache in bytes */ sizeBytes: number; /** Last cleanup timestamp */ lastCleanup: number; /** Cache version */ version: string; } /** * Cache configuration options. * * @category Utils */ export interface CacheConfig { /** Cache directory path */ cacheDir: string; /** TTL for external links in milliseconds */ externalLinksTtl: number; /** Maximum cache size in bytes */ maxSizeBytes: number; /** Enable cache compression */ compression: boolean; /** Cleanup interval in milliseconds */ cleanupInterval: number; } /** * Validation result caching system. * * Provides efficient caching of validation results with content-based invalidation, TTL for * external links, and automatic cleanup of stale entries. * * @category Utils * * @example * Basic usage * ```typescript * const cache = new ValidationCache(); * * // Check for cached result * const cached = await cache.get('/path/to/file.md', contentHash); * if (cached) { * console.log('Using cached validation result'); * return cached.result; * } * * // Perform validation and cache result * const result = await validateFile('/path/to/file.md'); * await cache.set('/path/to/file.md', contentHash, result); * ``` * * @example * Configuration```typescript * const cache = new ValidationCache({ * cacheDir: '.custom-cache', * externalLinksTtl: 12 * 60 * 60 * 1000, // 12 hours * maxSizeBytes: 50 * 1024 * 1024, // 50MB * }); * ```; */ export declare class ValidationCache { private config; private metadata; private hits; private misses; constructor(config?: Partial); /** * Get cached validation result for a file. * * @param filePath - Path to the file * @param contentHash - Hash of current file content * @param configHash - Hash of current validation configuration * @param gitCommit - Current git commit hash * * @returns Cached result if valid, undefined otherwise */ get(filePath: string, contentHash: string, configHash: string): Promise; /** * Store validation result in cache. * * @param filePath - Path to the file * @param contentHash - Hash of file content * @param result - Validation result to cache * @param configHash - Hash of validation configuration * @param gitCommit - Current git commit hash */ set(filePath: string, contentHash: string, result: ValidationResult, configHash: string, gitCommit?: string): Promise; /** * Invalidate cache entry for a file. * * @param filePath - Path to the file */ invalidate(filePath: string): Promise; /** Clear entire cache. */ clear(): Promise; /** * Get cache metadata and statistics. * * @returns Cache metadata */ getMetadata(): Promise; /** * Perform cache cleanup - remove expired and invalid entries. * * @returns Number of entries removed */ cleanup(): Promise; /** * Check if cache is enabled and accessible. * * @returns True if cache can be used */ isEnabled(): Promise; /** * Get cache file path for a given source file. * * @private */ private getCacheFilePath; /** * Read and parse cache file. * * @private */ private readCacheFile; /** * Write cache file. * * @private */ private writeCacheFile; /** * Check if cached result is still valid. * * @private */ private isCacheValid; /** * Check if cache entry should be removed during cleanup. * * @private */ private shouldRemoveFromCache; /** * Check if validation result contains external links. * * @private */ private hasExternalLinks; /** * Count links in validation result. * * @private */ private countLinksInResult; /** * Get current markmv version. * * @private */ private getVersion; } /** * Calculate hash of file content. * * @category Utils * * @param filePath - Path to the file * * @returns SHA-256 hash of file content */ export declare function calculateFileHash(filePath: string): Promise; /** * Calculate hash of configuration object. * * @category Utils * * @param config - Configuration object * * @returns SHA-256 hash of configuration */ export declare function calculateConfigHash(config: Record): string; //# sourceMappingURL=validation-cache.d.ts.map