CRITICAL CHECKPOINT - DO NOT PUSH TO GITHUB Recovery Status: - Successfully recovered brainy.ts from compiled JavaScript - All core v3.0 API methods functional (add, get, update, delete, relate, find, etc.) - Neural subsystem intact (562KB embedded patterns, NLP working) - Augmentation pipeline operational (20+ augmentations) - HNSW clustering system complete - Triple Intelligence compiled (needs constructor fix) - Test suite validates functionality Changes preserved: - 898 files with changes from last 3 days - 144,475 insertions - All augmentation improvements - All test coverage enhancements - Complete v3.0 feature set This is a LOCAL checkpoint only - contains recovered work after corruption incident. Created backup in .backups/brainy-full-20250910-151314.tar.gz Branch: recovery-checkpoint-20250910-151433 Date: Wed Sep 10 03:18:04 PM PDT 2025
93 lines
2.4 KiB
TypeScript
93 lines
2.4 KiB
TypeScript
/**
|
|
* SearchCache - Caches search results for improved performance
|
|
*/
|
|
import { SearchResult } from '../coreTypes.js';
|
|
export interface CacheEntry<T = any> {
|
|
results: SearchResult<T>[];
|
|
timestamp: number;
|
|
hits: number;
|
|
}
|
|
export interface SearchCacheConfig {
|
|
maxAge?: number;
|
|
maxSize?: number;
|
|
enabled?: boolean;
|
|
hitCountWeight?: number;
|
|
}
|
|
export declare class SearchCache<T = any> {
|
|
private cache;
|
|
private maxAge;
|
|
private maxSize;
|
|
private enabled;
|
|
private hitCountWeight;
|
|
private hits;
|
|
private misses;
|
|
private evictions;
|
|
constructor(config?: SearchCacheConfig);
|
|
/**
|
|
* Generate cache key from search parameters
|
|
*/
|
|
getCacheKey(query: any, k: number, options?: Record<string, any>): string;
|
|
/**
|
|
* Get cached results if available and not expired
|
|
*/
|
|
get(key: string): SearchResult<T>[] | null;
|
|
/**
|
|
* Cache search results
|
|
*/
|
|
set(key: string, results: SearchResult<T>[]): void;
|
|
/**
|
|
* Evict the oldest entry based on timestamp and hit count
|
|
*/
|
|
private evictOldest;
|
|
/**
|
|
* Clear all cached results
|
|
*/
|
|
clear(): void;
|
|
/**
|
|
* Invalidate cache entries that might be affected by data changes
|
|
*/
|
|
invalidate(pattern?: string | RegExp): void;
|
|
/**
|
|
* Smart invalidation for real-time data updates
|
|
* Only clears cache if it's getting stale or if data changes significantly
|
|
*/
|
|
invalidateOnDataChange(changeType?: 'add' | 'update' | 'delete'): void;
|
|
/**
|
|
* Check if cache entries have expired and remove them
|
|
* This is especially important in distributed scenarios where
|
|
* real-time updates might be delayed or missed
|
|
*/
|
|
cleanupExpiredEntries(): number;
|
|
/**
|
|
* Get cache statistics
|
|
*/
|
|
getStats(): {
|
|
hits: number;
|
|
misses: number;
|
|
evictions: number;
|
|
hitRate: number;
|
|
size: number;
|
|
maxSize: number;
|
|
enabled: boolean;
|
|
};
|
|
/**
|
|
* Enable or disable caching
|
|
*/
|
|
setEnabled(enabled: boolean): void;
|
|
/**
|
|
* Get memory usage estimate in bytes
|
|
*/
|
|
getMemoryUsage(): number;
|
|
/**
|
|
* Get current cache configuration
|
|
*/
|
|
getConfig(): SearchCacheConfig;
|
|
/**
|
|
* Update cache configuration dynamically
|
|
*/
|
|
updateConfig(newConfig: Partial<SearchCacheConfig>): void;
|
|
/**
|
|
* Evict entries if cache exceeds maxSize
|
|
*/
|
|
private evictIfNeeded;
|
|
}
|