Skip to content

Repository files navigation

@nebutra/cache

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/cache in Nebutra/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.

Installation

pnpm add @nebutra/cache

Strategies

StrategyDescription
ttlCacheStandard TTL-based caching
lockCacheDistributed locks
stampedeCache stampede prevention
lazyRefreshBackground refresh before expiry

Setup

UPSTASH_REDIS_REST_URL=https://...upstash.io
UPSTASH_REDIS_REST_TOKEN=...

Usage

TTL Cache

import{ttlCache}from"@nebutra/cache";// Get or set with TTLconstdata=awaitttlCache.getOrSet("user:123",async()=>awaitfetchUser(123),{ttl: 3600},// 1 hour);

Distributed Lock

import{lockCache}from"@nebutra/cache";// Acquire lockconstlock=awaitlockCache.acquire("process:order:456",{ttl: 30000,// 30 seconds});try{awaitprocessOrder(456);}finally{awaitlock.release();}

Stampede Protection

import{stampedeCache}from"@nebutra/cache";// Prevents multiple simultaneous cache rebuildsconstdata=awaitstampedeCache.getOrSet("expensive:query",async()=>awaitexpensiveQuery(),{ttl: 3600,lockTtl: 5000},);

Lazy Refresh

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

Multi-tenancy

All cache keys are automatically prefixed with tenant ID:

// Internally becomes: "tenant:org_123:user:456"awaitttlCache.get("user:456",{tenantId: "org_123"});

Related

License

MIT

About

Cache provider contracts and runtime helpers for Nebutra applications.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages