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
109 lines
3.2 KiB
TypeScript
109 lines
3.2 KiB
TypeScript
/**
|
|
* Cache Augmentation - Optional Search Result Caching
|
|
*
|
|
* Replaces the hardcoded SearchCache in Brainy with an optional augmentation.
|
|
* This reduces core size and allows custom cache implementations.
|
|
*
|
|
* Zero-config: Automatically enabled with sensible defaults
|
|
* Can be disabled or customized via augmentation registry
|
|
*/
|
|
import { BaseAugmentation } from './brainyAugmentation.js';
|
|
import { AugmentationManifest } from './manifest.js';
|
|
import { SearchCache } from '../utils/searchCache.js';
|
|
import type { GraphNoun } from '../types/graphTypes.js';
|
|
export interface CacheConfig {
|
|
maxSize?: number;
|
|
ttl?: number;
|
|
enabled?: boolean;
|
|
invalidateOnWrite?: boolean;
|
|
}
|
|
/**
|
|
* CacheAugmentation - Makes search caching optional and pluggable
|
|
*
|
|
* Features:
|
|
* - Transparent search result caching
|
|
* - Automatic invalidation on data changes
|
|
* - Memory-aware cache management
|
|
* - Zero-config with smart defaults
|
|
*/
|
|
export declare class CacheAugmentation extends BaseAugmentation {
|
|
readonly name = "cache";
|
|
readonly timing: "around";
|
|
readonly metadata: "none";
|
|
operations: ("search" | "find" | "similar" | "add" | "update" | "delete" | "clear" | "all")[];
|
|
readonly priority = 50;
|
|
readonly category: "core";
|
|
readonly description = "Transparent search result caching with automatic invalidation";
|
|
private searchCache;
|
|
constructor(config?: CacheConfig);
|
|
getManifest(): AugmentationManifest;
|
|
protected onInitialize(): Promise<void>;
|
|
protected onShutdown(): Promise<void>;
|
|
/**
|
|
* Execute augmentation - wrap operations with caching logic
|
|
*/
|
|
execute<T = any>(operation: string, params: any, next: () => Promise<T>): Promise<T>;
|
|
/**
|
|
* Handle search operation with caching
|
|
*/
|
|
private handleSearch;
|
|
/**
|
|
* Get cache statistics
|
|
*/
|
|
getStats(): {
|
|
enabled: boolean;
|
|
hits: number;
|
|
misses: number;
|
|
size: number;
|
|
memoryUsage: number;
|
|
} | {
|
|
memoryUsage: number;
|
|
hits: number;
|
|
misses: number;
|
|
evictions: number;
|
|
hitRate: number;
|
|
size: number;
|
|
maxSize: number;
|
|
enabled: boolean;
|
|
};
|
|
/**
|
|
* Clear the cache manually
|
|
*/
|
|
clear(): void;
|
|
/**
|
|
* Handle runtime configuration changes
|
|
*/
|
|
protected onConfigChange(newConfig: CacheConfig, oldConfig: CacheConfig): Promise<void>;
|
|
/**
|
|
* Clean up expired entries
|
|
*/
|
|
cleanupExpiredEntries(): number;
|
|
/**
|
|
* Invalidate cache when data changes
|
|
*/
|
|
invalidateOnDataChange(operation: 'add' | 'update' | 'delete'): void;
|
|
/**
|
|
* Get cache key for a query
|
|
*/
|
|
getCacheKey(query: any, options?: any): string;
|
|
/**
|
|
* Direct cache get
|
|
*/
|
|
get(key: string): any;
|
|
/**
|
|
* Direct cache set
|
|
*/
|
|
set(key: string, value: any): void;
|
|
/**
|
|
* Get the underlying SearchCache instance (for compatibility)
|
|
*/
|
|
getSearchCache(): SearchCache<GraphNoun> | null;
|
|
/**
|
|
* Get memory usage
|
|
*/
|
|
getMemoryUsage(): number;
|
|
}
|
|
/**
|
|
* Factory function for zero-config cache augmentation
|
|
*/
|
|
export declare function createCacheAugmentation(config?: CacheConfig): CacheAugmentation;
|