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 TTLconstdata=awaitttlCache.getOrSet("user:123",async()=>awaitfetchUser(123),{ttl: 3600},// 1 hour);import{lockCache}from"@nebutra/cache";// Acquire lockconstlock=awaitlockCache.acquire("process:order:456",{ttl: 30000,// 30 seconds});try{awaitprocessOrder(456);}finally{awaitlock.release();}import{stampedeCache}from"@nebutra/cache";// Prevents multiple simultaneous cache rebuildsconstdata=awaitstampedeCache.getOrSet("expensive:query",async()=>awaitexpensiveQuery(),{ttl: 3600,lockTtl: 5000},);import{lazyRefresh}from"@nebutra/cache";// Refresh in background before expiryconstdata=awaitlazyRefresh.getOrSet("api:data",async()=>awaitfetchFromApi(),{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"awaitttlCache.get("user:456",{tenantId: "org_123"});MIT