A lightweight and performant caching library providing simple TTL-based caches for single values and key-value maps.
Node.js 18 or newer is required.
npm install @sodiumlabs/cacheCache
import { Cache } from "@sodiumlabs/cache";
// values are cached for 60s:
const cache = new Cache({ ttl: 60_000 });
cache.set("some key", 10);
cache.get("some key"); // 10
cache.has("some key"); // true
cache.set("some key", 10, 10_000); // override the default TTL with 10s
await sleep(11_000);
cache.has("some key"); // falseValueCache
import { ValueCache } from "@sodiumlabs/cache";
const value = new ValueCache({ ttl: 10_000 }).set("some value");
value.get(); // "some value"
await sleep(11_000);
value.get(); // undefinedNeed help with the module? Ask on our support server!