supa-seed
Version:
A constraint-aware, framework-agnostic database seeding framework with deep PostgreSQL business logic discovery and MakerKit integration support
168 lines • 4.89 kB
TypeScript
/**
* Detection Result Caching System for Epic 2: Smart Platform Detection Engine
* Provides caching and reuse capabilities for detection results to improve performance
* Part of Task 2.3.4: Add detection result caching and reuse capabilities
*/
import type { UnifiedDetectionResult } from './detection-integration';
import type { AutoConfigurationResult } from './auto-configurator';
/**
* Cache entry for detection results
*/
export interface DetectionCacheEntry {
/** Unique cache key */
key: string;
/** Database schema hash for invalidation */
schemaHash: string;
/** Database URL for validation */
databaseUrl: string;
/** Detection results */
detectionResults: UnifiedDetectionResult;
/** Auto-configuration results */
autoConfiguration?: AutoConfigurationResult;
/** Cache metadata */
metadata: {
/** Creation timestamp */
createdAt: string;
/** Last access timestamp */
lastAccessedAt: string;
/** Access count */
accessCount: number;
/** Detection engine version */
engineVersion: string;
/** Cache TTL in milliseconds */
ttl: number;
/** Confidence level for cache validity */
confidenceLevel: string;
};
}
/**
* Cache configuration options
*/
export interface DetectionCacheOptions {
/** Cache directory path */
cacheDir: string;
/** Default TTL for cache entries (ms) */
defaultTTL: number;
/** Maximum cache size in bytes */
maxCacheSize: number;
/** Maximum number of cache entries */
maxEntries: number;
/** Enable cache compression */
enableCompression: boolean;
/** Cache invalidation strategy */
invalidationStrategy: 'time' | 'schema_change' | 'hybrid';
/** Minimum confidence level to cache */
minConfidenceToCache: number;
}
/**
* Cache statistics
*/
export interface CacheStatistics {
/** Total cache entries */
totalEntries: number;
/** Cache size in bytes */
cacheSize: number;
/** Cache hit rate */
hitRate: number;
/** Total cache hits */
totalHits: number;
/** Total cache misses */
totalMisses: number;
/** Average cache age */
averageAge: number;
/** Oldest cache entry age */
oldestEntry: number;
/** Most frequently accessed entry */
mostFrequentKey: string;
}
/**
* Main Detection Cache Manager
*/
export declare class DetectionCacheManager {
private cacheDir;
private options;
private statistics;
constructor(options?: Partial<DetectionCacheOptions>);
/**
* Generate cache key for detection request
*/
generateCacheKey(databaseUrl: string, schemaHash: string, options?: any): string;
/**
* Store detection results in cache
*/
store(cacheKey: string, databaseUrl: string, schemaHash: string, detectionResults: UnifiedDetectionResult, autoConfiguration?: AutoConfigurationResult, ttl?: number): Promise<void>;
/**
* Retrieve detection results from cache
*/
retrieve(cacheKey: string, databaseUrl?: string, currentSchemaHash?: string): Promise<DetectionCacheEntry | null>;
/**
* Check if a cache entry exists and is valid
*/
has(cacheKey: string, databaseUrl?: string, currentSchemaHash?: string): Promise<boolean>;
/**
* Remove a cache entry
*/
remove(cacheKey: string): Promise<void>;
/**
* Clear all cache entries
*/
clear(): Promise<void>;
/**
* Get cache statistics
*/
getStatistics(): Promise<CacheStatistics>;
/**
* Cleanup expired cache entries
*/
cleanupExpiredEntries(): Promise<number>;
/**
* Validate cache entry against current conditions
*/
private validateCacheEntry;
/**
* Enforce maximum cache size
*/
private enforceMaxSize;
/**
* Get cache file path for a given key
*/
private getCacheFilePath;
/**
* Normalize database URL for consistent caching
*/
private normalizeUrl;
/**
* Ensure cache directory exists
*/
private ensureCacheDirectory;
/**
* Merge options with defaults
*/
private mergeWithDefaults;
}
/**
* Utility functions for cache management
*/
export declare class DetectionCacheUtils {
/**
* Generate schema hash for cache invalidation
*/
static generateSchemaHash(client: any): Promise<string>;
/**
* Format cache statistics for display
*/
static formatStatistics(stats: CacheStatistics): string;
/**
* Format bytes for human-readable display
*/
private static formatBytes;
/**
* Format duration for human-readable display
*/
private static formatDuration;
}
/**
* Default cache options
*/
export declare const DEFAULT_CACHE_OPTIONS: DetectionCacheOptions;
//# sourceMappingURL=detection-cache.d.ts.map