Version 0.1.0
Overview
Updated 22 Oct 2026
@m2d/cache: High-performance, persistent caching engine using xxhash-wasm and IndexedDB for the @m2d ecosystem.
โจ 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.
with ๐ by Mayank Kumar Chaudhari