A lightweight cache for file metadata, ideal for processes that work on a specific set of files and only need to reprocess files that have changed since the last run
npx @tessl/cli install tessl/npm-file-entry-cache@10.1.0File Entry Cache is a lightweight cache for file metadata, ideal for processes that work on a specific set of files and only need to reprocess files that have changed since the last run. It efficiently monitors file modifications using timestamps and optional checksums, with persistent storage support.
npm install file-entry-cacheimport fileEntryCache, { FileEntryCache, create, createFromFile } from "file-entry-cache";For CommonJS:
const fileEntryCache = require("file-entry-cache");
const { FileEntryCache, create, createFromFile } = require("file-entry-cache");import { create } from "file-entry-cache";
// Create a cache instance
const cache = create("my-cache");
// Check if a file has changed
const fileDescriptor = cache.getFileDescriptor("src/app.js");
if (fileDescriptor.changed) {
console.log("File has changed, reprocessing...");
// Process the file
} else {
console.log("File unchanged, skipping...");
}
// Save cache to disk and clean up missing files
cache.reconcile();File Entry Cache is built around several key components:
FileEntryCache class that manages file metadata and change detectionEssential file caching functionality for tracking file changes and managing cache state.
class FileEntryCache {
constructor(options?: FileEntryCacheOptions);
getFileDescriptor(filePath: string, options?: GetFileDescriptorOptions): FileDescriptor;
hasFileChanged(filePath: string): boolean;
reconcile(): void;
}
function create(
cacheId: string,
cacheDirectory?: string,
useCheckSum?: boolean,
currentWorkingDirectory?: string
): FileEntryCache;
function createFromFile(
filePath: string,
useCheckSum?: boolean,
currentWorkingDirectory?: string
): FileEntryCache;Advanced operations for analyzing multiple files and performing bulk cache operations.
interface AnalyzedFiles {
changedFiles: string[];
notFoundFiles: string[];
notChangedFiles: string[];
}
class FileEntryCache {
analyzeFiles(files: string[]): AnalyzedFiles;
getUpdatedFiles(files: string[]): string[];
normalizeEntries(files?: string[]): FileDescriptor[];
}Configuration options, path utilities, and advanced cache management features.
interface FileEntryCacheOptions {
currentWorkingDirectory?: string;
useModifiedTime?: boolean;
useCheckSum?: boolean;
hashAlgorithm?: string;
cache?: FlatCacheOptions;
}
class FileEntryCache {
createFileKey(filePath: string, options?: { currentWorkingDirectory?: string }): string;
getAbsolutePath(filePath: string, options?: { currentWorkingDirectory?: string }): string;
getHash(buffer: Buffer): string;
}interface FileDescriptor {
key: string;
changed?: boolean;
meta: FileDescriptorMeta;
notFound?: boolean;
err?: Error;
}
interface FileDescriptorMeta {
size?: number;
mtime?: number;
hash?: string;
data?: unknown;
}
interface GetFileDescriptorOptions {
useCheckSum?: boolean;
useModifiedTime?: boolean;
currentWorkingDirectory?: string;
}
interface AnalyzedFiles {
changedFiles: string[];
notFoundFiles: string[];
notChangedFiles: string[];
}