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
| Property | Type | Required | Description |
|---|---|---|---|
| jitterTtl | Object | optional | TTL jitter to prevent simultaneous expiration |
| circuitBreaker | Object | optional | Circuit breaker for backend protection |
| lockout | Object | optional | Lock-based stampede prevention |
CacheConfig
Top-level application cache configuration
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| enabled | boolean | ✅ | Enable application-level caching |
| tiers | Object[] | ✅ | Ordered cache tier hierarchy |
| invalidation | Object[] | ✅ | Cache invalidation rules |
| prefetch | boolean | ✅ | Enable cache prefetching |
| compression | boolean | ✅ | Enable data compression in cache |
| encryption | boolean | ✅ | Enable encryption for cached data |
CacheConsistency
Distributed cache write consistency strategy
Allowed Values
write_throughwrite_behindwrite_aroundrefresh_ahead
CacheInvalidation
Rule defining when and how cached entries are invalidated
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| trigger | Enum<'create' | 'update' | 'delete' | 'manual'> | ✅ | Event that triggers invalidation |
| scope | Enum<'key' | 'pattern' | 'tag' | 'all'> | ✅ | Invalidation scope |
| pattern | string | optional | Key pattern for pattern-based invalidation |
| tags | string[] | optional | Cache tags to invalidate |
CacheStrategy
Cache eviction strategy
Allowed Values
lrulfufifottladaptive
CacheTier
Configuration for a single cache tier in the hierarchy
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| name | string | ✅ | Unique cache tier name |
| type | Enum<'memory' | 'redis' | 'memcached' | 'cdn'> | ✅ | Cache backend type |
| maxSize | number | optional | Max size in MB |
| ttl | number | ✅ | Default TTL in seconds |
| strategy | Enum<'lru' | 'lfu' | 'fifo' | 'ttl' | 'adaptive'> | ✅ | Eviction strategy |
| warmup | boolean | ✅ | Pre-populate cache on startup |
CacheWarmup
Cache warmup strategy
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| enabled | boolean | ✅ | Enable cache warmup |
| strategy | Enum<'eager' | 'lazy' | 'scheduled'> | ✅ | Warmup strategy: eager (at startup), lazy (on first access), scheduled (cron) |
| schedule | string | optional | Cron expression for scheduled warmup |
| patterns | string[] | optional | Key patterns to warm up (e.g., "user:", "config:") |
| concurrency | number | ✅ | Maximum concurrent warmup operations |
DistributedCacheConfig
Distributed cache configuration with consistency and avalanche prevention
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| enabled | boolean | ✅ | Enable application-level caching |
| tiers | Object[] | ✅ | Ordered cache tier hierarchy |
| invalidation | Object[] | ✅ | Cache invalidation rules |
| prefetch | boolean | ✅ | Enable cache prefetching |
| compression | boolean | ✅ | Enable data compression in cache |
| encryption | boolean | ✅ | Enable encryption for cached data |
| consistency | Enum<'write_through' | 'write_behind' | 'write_around' | 'refresh_ahead'> | optional | Distributed cache consistency strategy |
| avalanchePrevention | Object | optional | Cache avalanche and stampede prevention |
| warmup | Object | optional | Cache warmup strategy |