or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

configuration.mdcore-operations.mdfile-analysis.mdindex.md
tile.json

tessl/npm-file-entry-cache

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

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/file-entry-cache@10.1.x

To install, run

npx @tessl/cli install tessl/npm-file-entry-cache@10.1.0

index.mddocs/

File Entry Cache

File 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.

Package Information

  • Package Name: file-entry-cache
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install file-entry-cache

Core Imports

import fileEntryCache, { FileEntryCache, create, createFromFile } from "file-entry-cache";

For CommonJS:

const fileEntryCache = require("file-entry-cache");
const { FileEntryCache, create, createFromFile } = require("file-entry-cache");

Basic Usage

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();

Architecture

File Entry Cache is built around several key components:

  • Cache Instance: Main FileEntryCache class that manages file metadata and change detection
  • File Descriptors: Objects containing file metadata (size, modification time, hash) and change status
  • Persistence Layer: Integration with flat-cache for disk storage and retrieval
  • Change Detection: Multiple strategies including modification time and checksums
  • Path Handling: Support for both relative and absolute file paths with working directory resolution

Capabilities

Core Cache Operations

Essential 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;

Core Cache Operations

File Analysis and Bulk Operations

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[];
}

File Analysis

Configuration and Utilities

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;
}

Configuration & Utilities

Types

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[];
}