@managani/cache
v0.1.5
Published
Shared Memcached cache and MongoDB coordination primitives
Maintainers
Readme
@managani/cache
Shared CommonJS Memcached cache and MongoDB coordination primitives for Managani applications.
const { createCache } = require("@managani/cache");
const cache = createCache({
servers: [
"cache-memcached-1:11211",
"cache-memcached-2:11211",
"cache-memcached-3:11211",
],
namespace: "product:v3",
l1: { maxBytes: 16 * 1024 * 1024, maxTtlMs: 2000 },
});
await cache.set("key", { value: true }, { ttlMs: 300000 });
const value = await cache.get("key");Values use a versioned JSON envelope. Objects, arrays, dates, buffers, null,
primitives, and bigints retain their types. Values above 64 KiB use fast
compression when it saves at least 10%; values above 3.5 MiB on wire are skipped.
The cache exposes get, getMany, set, setMany, delete,
invalidateScope, getOrLoad, atomic add, increment, decrement,
consumeOnce, advisory acquireLease, health, and close.
Ordinary backend failures return misses or unsuccessful writes. consumeOnce
probes the whole cluster and fails closed while any node is degraded.
Use createMongoCoordinator({ db }) for token-checked locks, bounded
semaphores, and cooldowns whose loss could affect correctness. It uses primary
reads, atomic writes, and a TTL index.
