@reliverse/reche is a lightweight, universal caching library for Node, browsers, and beyond. Inspired by the simplicity of in-memory caching with optional TTL, Reche makes it easy to manage, store, and retrieve cached data no matter the runtime.
๐ฆ NPM โข โจ GitHub โข ๐ฌ Discord
Caching shouldn't be complicated. Whether you're targeting Node, Bun, or the browser, Reche offers a consistent, minimal interface for storing data with optional TTL (time-to-live).
- Works in both Node and Browser environments
- Adds optional TTL handling with auto-expiration
- Provides an in-memory adapter and a web-storage adapter
- Offers a universal adapter that auto-detects the environment
- Written in TypeScript for type-safety and easy integration
โ ๏ธ Heads up!
The full suite of features is still in progress forv1.0.0.
If you have suggestions or spot an issue, please let us know on Discord or via GitHub Issues.
Your feedback shapes the future of Reche!
- โป๏ธ Easy-to-use in-memory caching
- ๐ Automatic browser/localStorage detection
- โฐ TTL support for auto-expiration of cache entries
- ๐ฆ Universal adapter that picks the best storage for you
- ๐ Pluggable system for adding custom adapters (e.g., Redis, custom DB)
- ๐งญ Fully typed for TypeScript or plain JS usage
- ๐ก Safe by default โ gracefully falls back when web storage is unavailable
Node.js:
Provides memory-based CacheAdapter.
bun add @reliverse/reche
# bun โข pnpm โข yarn โข npmBun:
Provides Redis-based adapter leveraging Bun's RedisClient.
bun add @reliverse/reche-bunBrowser:
Provides the browser-based WebStorageAdapter plus a universal adapter.
bun add @reliverse/reche-webimport { createUniversalCacheAdapter } from "@reliverse/reche";
// Create a universal cache that tries localStorage in browsers,
// or memory when localStorage isn't available (e.g., Node)
const cache = createUniversalCacheAdapter();
// Store a greeting
cache.set("greeting", "Hello World");
// Retrieve it
console.log(cache.get("greeting")); // "Hello World"import { createMemoryCacheAdapter } from "@reliverse/reche";
const memoryCache = createMemoryCacheAdapter();
// Cache a value for 5 seconds
memoryCache.set("tempKey", { foo: "bar" }, 5000);
console.log(memoryCache.get("tempKey")); // { foo: "bar" }
// After 5 seconds:
setTimeout(() => {
console.log(memoryCache.get("tempKey")); // undefined (expired)
}, 5000);import { createMemoryCacheAdapter } from "@reliverse/reche";
const memoryCache = createMemoryCacheAdapter();
// Basic usage
memoryCache.set("count", 1);
console.log(memoryCache.get("count")); // 1
memoryCache.remove("count");
memoryCache.clear(); // remove everythingimport { createWebStorageAdapter } from "@reliverse/reche";
// By default uses window.localStorage
const webCache = createWebStorageAdapter();
webCache.set("sessionToken", "abc123");
console.log(webCache.get("sessionToken")); // "abc123"import { createUniversalCacheAdapter } from "@reliverse/reche";
// Automatically picks an adapter (web or memory)
const universalCache = createUniversalCacheAdapter();
// Or pass your own adapter:
import { createMemoryCacheAdapter } from "@reliverse/reche";
const customUniversal = createUniversalCacheAdapter(createMemoryCacheAdapter());import { createMemoryCacheAdapter } from "@reliverse/reche";
const cache = createMemoryCacheAdapter();
cache.set("randomNumber", Math.random(), 3000);
console.log(cache.get("randomNumber")); // e.g. 0.12345
setTimeout(() => {
console.log(cache.get("randomNumber")); // undefined (after TTL expires)
}, 3000);import { createWebStorageAdapter } from "@reliverse/reche";
const webCache = createWebStorageAdapter(); // uses localStorage by default
webCache.set("theme", "dark");
console.log(webCache.get("theme")); // "dark"
webCache.remove("theme");- Custom Adapters example (e.g., Redis, IndexedDB)
- Advanced TTL strategies (refresh on get, sliding expiration, etc.)
- Serialization customization (e.g., custom JSON parse/stringify or msgpack)
- Better Error Handling for environment detection
- Unit Tests & coverage
- Documentation site with real-life usage patterns
- ๐ Devs wanting simple caching for quick prototypes
- ๐๏ธโโ๏ธ Production apps needing a universal cache for Node and browser
- ๐งฑ Library authors who want a minimal caching solution
- โ๏ธ People who want to centralize caching logic in one place
localforageโ for advanced browser storagenode-cacheโ in-memory caching for Nodeidbโ typed wrapper for IndexedDB
- MIT ยฉ blefnk Nazar Kornienko
- Part of the Reliverse ecosystem
๐ This README was proudly generated with Remdn