# Cache-Control

> Cache-Control header directives with max-age, stale-while-revalidate, and immutable.

- Name: `cache-control`
- Categories: api
- Detail page: https://open-types.dev/types/cache-control

## Install

```bash
# Types only
npx shadcn add @open-types/cache-control

# Types + Zod v4 validators
npx shadcn add @open-types/cache-control-zod

# Types + real-world examples
npx shadcn add @open-types/cache-control-examples
```

## Types

```typescript
export interface CacheControlDirectives {
  public?: boolean;
  private?: boolean;
  no_cache?: boolean;
  no_store?: boolean;
  max_age?: number;
  s_maxage?: number;
  must_revalidate?: boolean;
  proxy_revalidate?: boolean;
  immutable?: boolean;
  stale_while_revalidate?: number;
  stale_if_error?: number;
}
```

## Zod validator

```typescript
import * as z from "zod";
import type { CacheControlDirectives } from "../types/cache-control";

export const cacheControlDirectivesSchema = z.object({
  public: z.boolean().optional(),
  private: z.boolean().optional(),
  no_cache: z.boolean().optional(),
  no_store: z.boolean().optional(),
  max_age: z.number().optional(),
  s_maxage: z.number().optional(),
  must_revalidate: z.boolean().optional(),
  proxy_revalidate: z.boolean().optional(),
  immutable: z.boolean().optional(),
  stale_while_revalidate: z.number().optional(),
  stale_if_error: z.number().optional(),
}) satisfies z.ZodType<CacheControlDirectives>;

export type { CacheControlDirectives } from "../types/cache-control";
```

## Examples

```typescript
// Source: https://datatracker.ietf.org/doc/html/rfc9111#name-cache-control
// Captured: 2026-05
import type { CacheControlDirectives } from "../types/cache-control";

export const cacheControlDirectivesExamples = {
  publicCdn: {
    public: true,
    max_age: 3600,
    s_maxage: 86400,
    stale_while_revalidate: 86400,
  } satisfies CacheControlDirectives,
  privateUser: {
    private: true,
    max_age: 0,
    must_revalidate: true,
  } satisfies CacheControlDirectives,
  noStore: { no_store: true, no_cache: true } satisfies CacheControlDirectives,
  immutable: {
    public: true,
    max_age: 31_536_000,
    immutable: true,
  } satisfies CacheControlDirectives,
  staleIfError: {
    public: true,
    max_age: 600,
    stale_if_error: 86400,
    proxy_revalidate: true,
  } satisfies CacheControlDirectives,
  empty: {} satisfies CacheControlDirectives,
} as const;
```
