Caching

Use namespaced portable caches with typed serialization, tag invalidation, and explicit stampede-protection capabilities across Redis, Workers, and local runtimes.

Approaches

Namespaced key-value caching

Keep application and environment boundaries in every physical key while preserving direct access to the configured storage client.

Packages

@playstack/cache

Stampede-protected remember

Load a missing value once with process-local or distributed locking declared by the selected adapter.

Frameworks and integrations

Tag invalidation

Invalidate related keys through versioned tags without provider-specific key scans or hidden global state.

Frameworks and integrations

framework

Next.js

Compose Playstack server contracts, React bindings, SSR handoff, and route adapters at the Next.js application edge.

framework

NestJS

Connect portable Playstack capabilities to dependency injection, guards, decorators, request context, workers, and lifecycle hooks.

integration

Redis

Use Redis for distributed caches, rate-limit counters, and BullMQ-backed jobs while keeping application policy portable.

framework

Cloudflare Workers

Run portable contracts in Web-standard runtimes with explicit Workers KV, R2, Queues and Durable Object adapters.

integration

Cloudflare Workers KV

Use an application-supplied Workers KV binding for namespaced cache storage with explicitly eventual capabilities.

Package reference

@playstack/cache

Own the namespace

Every cache instance receives an application and environment identity. Physical keys therefore remain safe when multiple products, previews, workers, or test suites share one provider.

ts
import { createCache } from '@playstack/cache'
import { RedisCacheStorage } from '@playstack/cache/redis'

export const cache = createCache({
  app: 'billing',
  environment: 'production',
  driver: new RedisCacheStorage(redis),
  lockTtlMs: 30_000,
})

const plan = await cache.remember(
  'plans:pro',
  60_000,
  () => plans.load('pro'),
)

Invalidate by domain fact

ts
const accountCache = cache.tags('accounts', `account:${account.id}`)

await accountCache.put('summary', summary, 60_000)
await accountCache.flush()

Tag versions avoid provider key scans. An adapter declares whether invalidation is immediate or eventual and whether stampede protection is process-local or distributed, so an application can reject a capability mismatch during configuration.

Keep failure policy visible

Serialization, lock timeouts, and provider unavailability have distinct stable errors. The application decides whether a specific read may fail open, retry, or bypass the cache; the package does not silently turn an infrastructure failure into a miss.

Layer memory over Redis deliberately

The native Cache guide covers direct ioredis binding, bounded memory/Redis storage, native batches, remaining-TTL fills and combined logical statistics. Configure a finite L1 staleness ceiling; another process's overwrite can remain stale until that ceiling. This is not a coherent authorization or revocation store.

Opt-in background writes support immediate provisional reads through their own helper, with separate memory/pending-work budgets and an explicit shutdown drain. Admission is lossy, not a Redis acknowledgment. Unknown write failure stops the helper and clears provisional values rather than automatically retrying an uncertain write; ordinary cache writes and remember remain acknowledged.

Go

Playstack Pro tag
OriginsPricingBlogChangelogStatus

© 2026 Playstack. All rights reserved.

With OSS

By

Commune Software