UNPKG

@nxworker/workspace

Version:

Nx plugin providing generators for managing workspace files, including the move-file generator for safely moving files between projects while updating all imports

55 lines (54 loc) 1.86 kB
import { Tree } from '@nx/devkit'; /** * In-memory cache for Tree read operations to reduce File I/O overhead. * * This cache stores the results of tree.read() and tree.children() calls * to avoid redundant File I/O. The cache is invalidated when files are modified. * * This optimization targets the 30-40% of time spent on File I/O operations * and complements existing caching strategies: * - AST caching (parsed ASTs and content) * - File existence caching (tree.exists results) * - Project source files caching (file lists per project) */ export declare class TreeReadCache { private contentCache; private childrenCache; /** * Cached wrapper for tree.read() * @param tree - The Tree instance * @param filePath - Path to the file * @param encoding - File encoding * @returns File content or null if file doesn't exist */ read(tree: Tree, filePath: string, encoding?: BufferEncoding): string | null; /** * Cached wrapper for tree.children() * @param tree - The Tree instance * @param dirPath - Directory path * @returns Array of child file/directory names */ children(tree: Tree, dirPath: string): string[]; /** * Invalidates cache entry for a file after it's been written * @param filePath - Path to invalidate */ invalidateFile(filePath: string): void; /** * Invalidates cache entry for a directory * @param dirPath - Directory path to invalidate */ invalidateDirectory(dirPath: string): void; /** * Clears all caches. Should be called when starting a new operation. */ clear(): void; /** * Returns cache statistics for monitoring/debugging */ getStats(): { contentCacheSize: number; childrenCacheSize: number; }; } export declare const treeReadCache: TreeReadCache;