---
title: Cache
description: Cache protocol schemas
---

{/* ⚠️  AUTO-GENERATED — DO NOT EDIT. Run build-docs.ts to regenerate. Hand-written docs go in content/docs/guides/. */}

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

<Callout type="info">
**Source:** `packages/spec/src/system/cache.zod.ts`
</Callout>

## TypeScript Usage

```typescript
import { CacheAvalanchePrevention, CacheConfig, CacheConsistency, CacheInvalidation, CacheStrategy, CacheTier } from '@objectstack/spec/system';
import type { CacheAvalanchePrevention, CacheConfig, CacheConsistency, CacheInvalidation, CacheStrategy, CacheTier } 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_through`
* `write_behind`
* `write_around`
* `refresh_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

* `lru`
* `lfu`
* `fifo`
* `ttl`
* `adaptive`


---

## 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 |


---

