Skip to content

reliverse/reche

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

2 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Reliverse Reche

@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

๐Ÿ’ก Why Reche?

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 for v1.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!

โœจ Features

  • โ™ป๏ธ 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

๐Ÿ“ฆ Installation

Node.js:

Provides memory-based CacheAdapter.

bun add @reliverse/reche
# bun โ€ข pnpm โ€ข yarn โ€ข npm

Bun:

Provides Redis-based adapter leveraging Bun's RedisClient.

bun add @reliverse/reche-bun

Browser:

Provides the browser-based WebStorageAdapter plus a universal adapter.

bun add @reliverse/reche-web

๐Ÿš€ Usage

Quick Start

import { 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"

With TTL

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

๐Ÿ”ง API Overview

Memory Adapter

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 everything

Web Storage Adapter

import { createWebStorageAdapter } from "@reliverse/reche";

// By default uses window.localStorage
const webCache = createWebStorageAdapter();

webCache.set("sessionToken", "abc123");
console.log(webCache.get("sessionToken")); // "abc123"

Universal Adapter

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

๐Ÿงช Examples

Example: Node-Only Script

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

Example: Browser-Only (localStorage)

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

๐Ÿ”ฎ Roadmap

  • 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

๐Ÿ‘ถ Who's It For?

  • ๐Ÿ†• 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

๐Ÿง  Similar Projects

  • localforage โ€” for advanced browser storage
  • node-cache โ€” in-memory caching for Node
  • idb โ€” typed wrapper for IndexedDB

๐Ÿ’ฌ Community

๐Ÿ“„ License

๐ŸŒ€ This README was proudly generated with Remdn

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published