@m2d/cache
v0.1.0
Published
High-performance persistent caching engine for md2docx using xxhash-wasm and IndexedDB.
Maintainers
Readme
@m2d/cache
@m2d/cache: High-performance, persistent caching engine using xxhash-wasm and IndexedDB for the
@m2decosystem.
✨ Features
- ⚡ 64-bit Non-Cryptographic Hashing: Uses
xxhash-wasmfor lightning-fast, collision-resistant cache key generation. - 💾 Multi-Tier Persistence: Supports memory-only, IndexedDB-only, or synchronized hybrid caching.
- 🛡️ Poisoned Cache Prevention: Built-in
shouldCachepredicate prevents caching failed promises, empty buffers, or placeholder errors. - 🔀 Parallel Compute & Fetch: Executes cache lookup and generation simultaneously for zero-latency hits.
- 🧹 Automatic Cleanup: Time-based LRU-style cleanup using
simpleCleanupbased on access timestamps.
📦 Installation
$ pnpm add @m2d/cacheor
$ npm install @m2d/cacheor
$ yarn add @m2d/cache🚀 Quick Start
import { createPersistentCache } from "@m2d/cache";
const fetchWithCache = createPersistentCache(
async (url: string) => {
const res = await fetch(url);
return res.json();
},
"api-cache",
{ cacheMode: "both" },
);
const data = await fetchWithCache("https://api.example.com/data");License
This library is licensed under the MIT open-source license.
