@synet/fs
Version:
Robust, battle-tested filesystem abstraction for Node.js
73 lines (72 loc) • 2.4 kB
TypeScript
import type { IAsyncFileSystem } from "./async-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 async file operations
* Dramatically improves performance by caching frequently accessed files
*/
export declare class CachedFileSystem implements IAsyncFileSystem {
private baseFileSystem;
private readCache;
private existsCache;
private dirCache;
private readonly options;
constructor(baseFileSystem: IAsyncFileSystem, 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;
exists(path: string): Promise<boolean>;
readFile(path: string): Promise<string>;
writeFile(path: string, data: string): Promise<void>;
deleteFile(path: string): Promise<void>;
deleteDir(path: string): Promise<void>;
readDir(dirPath: string): Promise<string[]>;
ensureDir(path: string): Promise<void>;
chmod(path: string, mode: number): Promise<void>;
clear?(dirPath: string): Promise<void>;
}
/**
* Convenience function to create a cached filesystem with common defaults
*/
export declare function createCachedFileSystem(baseFileSystem: IAsyncFileSystem, options?: CachedFileSystemOptions): CachedFileSystem;