ObjectStackObjectStack

Cache

Cache protocol schemas

Application-Level Cache Protocol

Multi-tier caching strategy for application data.

Supports Memory, Redis, Memcached, and CDN.

Caching in ObjectStack

Application Cache (system/cache.zod.ts) - This File

  • Purpose: Cache computed data, query results, aggregations

  • Technologies: Redis, Memcached, in-memory LRU

  • Configuration: TTL, eviction policies, cache warming

  • Use case: Cache expensive database queries, computed values

  • Scope: Application layer, server-side data storage

HTTP Cache (api/http-cache.zod.ts)

  • Purpose: Cache API responses at HTTP protocol level

  • Technologies: HTTP headers (ETag, Last-Modified, Cache-Control), CDN

  • Configuration: Cache-Control headers, validation tokens

  • Use case: Reduce API response time for repeated metadata requests

  • Scope: HTTP layer, client-server communication

@see ../../api/http-cache.zod.ts for HTTP-level caching

Source: packages/spec/src/system/cache.zod.ts

TypeScript Usage

import { CacheAvalanchePrevention, CacheConfig, CacheConsistency, CacheInvalidation, CacheStrategy, CacheTier, CacheWarmup, DistributedCacheConfig } from '@objectstack/spec/system';
import type { CacheAvalanchePrevention, CacheConfig, CacheConsistency, CacheInvalidation, CacheStrategy, CacheTier, CacheWarmup, DistributedCacheConfig } from '@objectstack/spec/system';

// Validate data
const result = CacheAvalanchePrevention.parse(data);

CacheAvalanchePrevention

Cache avalanche/stampede prevention configuration

Properties

PropertyTypeRequiredDescription
jitterTtlObjectoptionalTTL jitter to prevent simultaneous expiration
circuitBreakerObjectoptionalCircuit breaker for backend protection
lockoutObjectoptionalLock-based stampede prevention

CacheConfig

Top-level application cache configuration

Properties

PropertyTypeRequiredDescription
enabledbooleanEnable application-level caching
tiersObject[]Ordered cache tier hierarchy
invalidationObject[]Cache invalidation rules
prefetchbooleanEnable cache prefetching
compressionbooleanEnable data compression in cache
encryptionbooleanEnable encryption for cached data

CacheConsistency

Distributed cache write consistency strategy

Allowed Values

  • write_through
  • write_behind
  • write_around
  • refresh_ahead

CacheInvalidation

Rule defining when and how cached entries are invalidated

Properties

PropertyTypeRequiredDescription
triggerEnum<'create' | 'update' | 'delete' | 'manual'>Event that triggers invalidation
scopeEnum<'key' | 'pattern' | 'tag' | 'all'>Invalidation scope
patternstringoptionalKey pattern for pattern-based invalidation
tagsstring[]optionalCache tags to invalidate

CacheStrategy

Cache eviction strategy

Allowed Values

  • lru
  • lfu
  • fifo
  • ttl
  • adaptive

CacheTier

Configuration for a single cache tier in the hierarchy

Properties

PropertyTypeRequiredDescription
namestringUnique cache tier name
typeEnum<'memory' | 'redis' | 'memcached' | 'cdn'>Cache backend type
maxSizenumberoptionalMax size in MB
ttlnumberDefault TTL in seconds
strategyEnum<'lru' | 'lfu' | 'fifo' | 'ttl' | 'adaptive'>Eviction strategy
warmupbooleanPre-populate cache on startup

CacheWarmup

Cache warmup strategy

Properties

PropertyTypeRequiredDescription
enabledbooleanEnable cache warmup
strategyEnum<'eager' | 'lazy' | 'scheduled'>Warmup strategy: eager (at startup), lazy (on first access), scheduled (cron)
schedulestringoptionalCron expression for scheduled warmup
patternsstring[]optionalKey patterns to warm up (e.g., "user:", "config:")
concurrencynumberMaximum concurrent warmup operations

DistributedCacheConfig

Distributed cache configuration with consistency and avalanche prevention

Properties

PropertyTypeRequiredDescription
enabledbooleanEnable application-level caching
tiersObject[]Ordered cache tier hierarchy
invalidationObject[]Cache invalidation rules
prefetchbooleanEnable cache prefetching
compressionbooleanEnable data compression in cache
encryptionbooleanEnable encryption for cached data
consistencyEnum<'write_through' | 'write_behind' | 'write_around' | 'refresh_ahead'>optionalDistributed cache consistency strategy
avalanchePreventionObjectoptionalCache avalanche and stampede prevention
warmupObjectoptionalCache warmup strategy

On this page