@anymux/cache
v0.1.0
Published
Caching layer for AnyMux file systems
Maintainers
Readme
@anymux/cache
Cached file system wrapper for AnyMux. Transparent caching layer for any IFileSystem implementation.
Installation
pnpm add @anymux/cacheUsage
import { CachedFileSystem } from "@anymux/cache";
import { WebDavFileSystem } from "@anymux/webdav";
const remote = new WebDavFileSystem({ url: "https://dav.example.com" });
const fs = new CachedFileSystem(remote, {
maxSize: 50 * 1024 * 1024, // 50 MB cache
ttl: 60_000, // 60 second TTL
});
// First read hits remote, subsequent reads served from cache
const content = await fs.readFile("/data.json", "utf-8");API Overview
Wraps any IFileSystem with an in-memory cache to reduce remote calls.
- Read-through caching —
readFile,stat,readdirresults are cached - Write-through — writes update both cache and backing store
- TTL-based expiry — configurable time-to-live per entry
- Size limits — LRU eviction when cache exceeds
maxSize - Manual invalidation —
invalidate(path)andclear()methods
Configuration
maxSize— Maximum cache size in bytesttl— Time-to-live in millisecondscacheReaddirs— Whether to cache directory listings (default:true)
License
MIT
