UNPKG

@synet/fs

Version:

Robust, battle-tested filesystem abstraction for Node.js

73 lines (72 loc) 2.32 kB
import type { IFileSystem } from "./filesystem.interface"; /** * Cache configuration options */ export interface CachedFileSystemOptions { /** Maximum number of files to cache (default: 100) */ maxSize?: number; /** Time-to-live for cached entries in milliseconds (default: 5 minutes) */ ttl?: number; /** Whether to cache only read operations or also existence checks (default: true) */ cacheExists?: boolean; /** Whether to cache directory listings (default: true) */ cacheDirListing?: boolean; } /** * CachedFileSystem provides LRU caching with TTL for file operations * Dramatically improves performance by caching frequently accessed files */ export declare class CachedFileSystem implements IFileSystem { private baseFileSystem; private readCache; private existsCache; private dirCache; private readonly options; constructor(baseFileSystem: IFileSystem, options?: CachedFileSystemOptions); /** * Get cache statistics */ getCacheStats(): { readCache: { size: number; maxSize: number; entries: string[]; }; existsCache: { size: number; maxSize: number; entries: string[]; }; dirCache: { size: number; maxSize: number; entries: string[]; }; options: Required<CachedFileSystemOptions>; }; /** * Clear all caches */ clearCache(): void; /** * Invalidate cache for a specific file */ invalidateFile(path: string): void; /** * Invalidate cache for a directory and all its children */ invalidateDirectory(dirPath: string): void; existsSync(path: string): boolean; readFileSync(path: string): string; writeFileSync(path: string, data: string): void; deleteFileSync(path: string): void; deleteDirSync(path: string): void; readDirSync(dirPath: string): string[]; ensureDirSync(path: string): void; chmodSync(path: string, mode: number): void; clear?(dirPath: string): void; } /** * Convenience function to create a cached filesystem with common defaults */ export declare function createCachedFileSystem(baseFileSystem: IFileSystem, options?: CachedFileSystemOptions): CachedFileSystem;