Public mirror for @nebutra/cache from Nebutra/Nebutra-Sailor.
This repository is generated from the Nebutra Sailor monorepo. Package releases are cut from the monorepo and mirrored here for discovery, standalone cloning, and contribution intake.
- Canonical source:
packages/integrations/cacheinNebutra/Nebutra-Sailor - Package registry: npm and GitHub Packages
- Contributions: open issues or PRs here; maintainers port accepted changes back into the monorepo source package
Redis caching strategies for Upstash Redis.
pnpm add @nebutra/cache| Strategy | Description |
|---|---|
ttlCache |
Standard TTL-based caching |
lockCache |
Distributed locks |
stampede |
Cache stampede prevention |
lazyRefresh |
Background refresh before expiry |
UPSTASH_REDIS_REST_URL=https://...upstash.io
UPSTASH_REDIS_REST_TOKEN=...import { ttlCache } from "@nebutra/cache";
// Get or set with TTL
const data = await ttlCache.getOrSet(
"user:123",
async () => await fetchUser(123),
{ ttl: 3600 }, // 1 hour
);import { lockCache } from "@nebutra/cache";
// Acquire lock
const lock = await lockCache.acquire("process:order:456", {
ttl: 30000, // 30 seconds
});
try {
await processOrder(456);
} finally {
await lock.release();
}import { stampedeCache } from "@nebutra/cache";
// Prevents multiple simultaneous cache rebuilds
const data = await stampedeCache.getOrSet(
"expensive:query",
async () => await expensiveQuery(),
{ ttl: 3600, lockTtl: 5000 },
);import { lazyRefresh } from "@nebutra/cache";
// Refresh in background before expiry
const data = await lazyRefresh.getOrSet(
"api:data",
async () => await fetchFromApi(),
{ ttl: 3600, refreshAt: 0.8 }, // Refresh at 80% of TTL
);All cache keys are automatically prefixed with tenant ID:
// Internally becomes: "tenant:org_123:user:456"
await ttlCache.get("user:456", { tenantId: "org_123" });MIT