# Cache

Purge the cache of a domain, write the rules that decide what is cached, and change its cache settings.

This part of the API controls the cache of one domain: what is cached, for how long, and how to remove it. The paths start with `/v2/cdn/cache/{domain_public_id}/`, where the id is the public id of the domain, taken from [the domains list](https://docs.diamwall.com/products/domains/#list-your-domains).

- [Purge](#purge-the-cache): Remove everything, a path prefix or a list of URLs from the cache.
- [Cache rules](#cache-rules): List, create, edit, delete and reorder the rules that cache or bypass.
- [Rule options](#rule-options): See what a rule can use on this domain, and the defaults.
- [Cache settings](#cache-settings): Read and change the cache configuration of the domain.

The examples on this page use these shell variables:

```bash
export DIAMWALL_API_KEY="your key"
export CACHE="https://api.diamwall.com/v2/cdn/cache/your-domain-public-id"
```

## Purge the cache

[`POST /v2/cdn/cache/{domain_public_id}/actions/cache-purge/` in the API reference](https://docs.diamwall.com/api/#tag/cache/POST/v2/cdn/cache/{domain_public_id}/actions/cache-purge/)

A purge takes a body with a `mode`, and an `Idempotency-Key` header that you make up.

| `mode` | Other field | What is purged |
| --- | --- | --- |
| `everything` | None | The whole cache of the domain |
| `prefix` | `prefix` | Every path that begins with the prefix |
| `url` | `urls` | The URLs of the list, 1 to 30 of them |

**Everything**

```bash
curl -X POST "$CACHE/actions/cache-purge/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: purge-all-2026-11-23-a1" \
  -d '{ "mode": "everything" }'
```

**Prefix**

```bash
curl -X POST "$CACHE/actions/cache-purge/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: purge-images-2026-11-23-b2" \
  -d '{ "mode": "prefix", "prefix": "/images/" }'
```

**URLs**

```bash
curl -X POST "$CACHE/actions/cache-purge/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: purge-urls-2026-11-23-c3" \
  -d '{
    "mode": "url",
    "urls": [
      "https://example.com/image-1.png",
      "https://www.example.com/image-2.png"
    ]
  }'
```

- A field of another mode is refused: `prefix` with `mode: "url"`, or either field with `mode: "everything"`.
- `prefix` begins with `/` and not with `//`, and holds at most 2048 bytes. Send it already URL-encoded, with no query string, no fragment, no spaces and no `.` or `..` segments. It is used exactly as you send it.
- Each URL is absolute, `http` or `https`, at most 2048 bytes, with no credentials, no fragment and no port other than 80 or 443. No URL comes twice.
- Each URL belongs to the domain of the path, or to a name under it. A URL of another domain answers `400 INVALID_REQUEST` with `urls` in `fields`.
- The whole body holds at most 32768 bytes. Thirty URLs of the largest size do not fit.

### Read the answer

```json
{
  "revision": null,
  "consistency": "degraded",
  "publication": { "status": "unknown", "rollout": "unknown" },
  "idempotency_replayed": false,
  "data": {
    "mode": "url",
    "total": 6,
    "succeeded": 5,
    "failed": 1,
    "results": [
      { "total": 3, "succeeded": 3, "failed": 0 },
      { "total": 3, "succeeded": 2, "failed": 1 }
    ]
  }
}
```

- `data.results` has one entry for each target, in the order of `urls`. `everything` and `prefix` have one entry.
- The counts are servers, not bytes and not cached objects.
- A `200` can be a purge that failed in part. When `failed` is above zero the answer says `consistency: "degraded"`. Show it as it is. It is not an error.
- `revision` is `null` and there is no `ETag`.

> **A purge is not undone**
> What was purged does not come back. Do not send the request again to make sure. The answer tells you what happened.

### The Idempotency-Key

The key is 16 to 128 characters. The first is a letter or a digit, and the others are letters, digits, `.`, `_`, `:` or `-`. Make one key for each purge that a person asks for.

Sending the same key with the same body again within 24 hours purges nothing. You get the first answer back, with `idempotency_replayed: true`. After 24 hours no replay is promised, and the same request may purge again.

Some answers leave the outcome uncertain. What to do depends on the code:

| Answer | Did it run? | What to do |
| --- | --- | --- |
| `502 FILE_SERVER_OUTCOME_UNKNOWN` | Maybe. The answer was lost. | Send the same request again with the same key, within 24 hours. |
| `503 ACTION_UNAVAILABLE` | Not confirmed. The cache servers could not be reached. | Back off, then send the same request again with the same key, within 24 hours. |
| `409 ACTION_OUTCOME_UNKNOWN` | Unknown. | Stop. Show the purge as uncertain. Do not repeat it and do not make a new key. |
| `409 IDEMPOTENCY_CONFLICT` | Unknown. The key may belong to another body. | Stop retrying. Do not change the key to get past it. |
| `429 ACTION_HISTORY_FULL` | No. | Do not send it again. Waiting does not end it. |
| `FILE_SERVER_V2_ERROR` with a `request_id` | Unconfirmed. | Show the purge as uncertain. Keep the `request_id` for support. |

A new key is only for a new purge that someone asks for later.

## Cache rules

A cache rule says which requests are cached and which bypass the cache. A domain holds at most 500 rules.

### What a rule is made of

| Field | What it is |
| --- | --- |
| `id` | Given by the API: `r_` and 32 hexadecimal digits |
| `name` | Required. One line, 1 to 128 bytes. No two rules have the same name |
| `description` | Optional. One line, at most 1024 bytes. An empty string clears it |
| `enabled` | Required. `true` applies the rule, `false` keeps it without applying it |
| `priority` | Optional. A whole number from 1 to 1000000. The lowest is evaluated first. Without it, a new rule is given one |
| `type` | Required. `all` for every request of the domain, `filter` for the requests that `expressions` select |
| `expressions` | Required with `filter`: 1 to 64 conditions |
| `action` | Required. What the rule does. `eligibility` inside it is `cache` or `bypass` |

Each condition in `expressions` has exactly four fields:

| Field | Allowed values |
| --- | --- |
| `type` | `main` for the first condition. `main`, `and` or `or` for the others |
| `field` | `ip`, `country`, `continent`, `asn`, `ua`, `cookie`, `hostname`, `referer`, `reqmethod`, `ssl`, `uri`, `fulluri`, `querystring`, `httpversion` |
| `operator` | `wildcard`, `equals`, `not_equals`, `contains`, `not_contains`, `starts_with`, `not_starts_with`, `ends_with`, `not_ends_with` |
| `value` | One line, 1 to 2048 bytes |

### What an action can hold

A rule that bypasses the cache has exactly `{ "eligibility": "bypass" }`. A rule that caches can add these fields:

| Field | Allowed values |
| --- | --- |
| `runtime_version` | The version of the cache policy of the rule, `1` or `2`. A new policy sends `2`. An edit sends the version the rule was read with |
| `edge_ttl` | `respect_origin`, `5m`, `30m`, `1h`, `4h`, `12h`, `1d`, `7d`, `30d`, `60d`, `90d`, `1y` |
| `browser_ttl` | `respect_origin`, `match_edge`, `5m`, `30m`, `1h`, `4h`, `12h`, `1d`, `7d`, `30d`, `1y` |
| `query_string` | `standard`, `sort`, `ignore_all` |
| `strip_cookies` | `true` removes the cookies of an answer before it is cached |
| `origin_cache_control` | `respect` or `ignore`. `ignore` also overrides `private`, `no-cache` and `no-store`, so use it only for content you know is public |
| `min_uses` | 1 to 1023: how many requests a key has before an answer is stored |
| `cache_retention` | `1d`, `7d`, `14d`, `30d`, `60d`, `90d`, `180d`, `365d`, `730d`: how long a copy is kept without being requested |
| `cache_statuses` | A list of 1 to 11 of: 200, 203, 204, 300, 301, 302, 303, 307, 308, 404, 410 |
| `revalidate` | `true` revalidates a stale copy with the origin |
| `stale_while_offline` | `true` serves a stale copy while the origin fails |
| `stale_while_revalidating` | `true` serves a stale copy while a fresh one is fetched |
| `auth_cookies` | The names of the cookies that mark a visitor as signed in: `patterns` (1 to 32 names, `*` allowed as the last character) and optionally `except` |
| `authenticated_fallback` | `true` serves a cached public copy to a signed-in visitor when the origin fails |
| `cache_key` | `host_uri`, kept for compatibility. A version 2 rule does not need it |

A few fields depend on each other. A request that breaks one of these answers `400 INVALID_REQUEST` and names the field:

- `cache_retention` is longer than a fixed `edge_ttl` in the same action. A year counts as 365 days, so `365d` with `1y` is refused.
- `authenticated_fallback: true` needs `auth_cookies` and `stale_while_offline: true` in the same action.
- Each name in `auth_cookies.except` is covered by one of the `patterns`.
- A bypass rule takes no `runtime_version`.
- With `runtime_version: 1`, `cache_retention` is `90d` and `cache_statuses` is `[200]`.

> **A field you leave out is not a reset**
> When a rule leaves out `edge_ttl`, `browser_ttl`, `query_string`, `strip_cookies`, `origin_cache_control`, `min_uses`, `cache_retention` or `cache_statuses`, it sets nothing for that field. Another matching rule that sets it still applies, and the default applies only when no matching rule sets it. The exception is `authenticated_fallback`: left out, it is off.

### Writes need the latest revision

Every answer that reads the rules, the list or one rule, has an `ETag` header. It is the revision of all the rules of the domain together. A create, edit, delete or reorder sends it back in `If-Match`, exactly as it came, quotes included.

```bash
ETAG=$(curl -s -o /dev/null -D - "$CACHE/rules/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  | tr -d '\r' | awk 'tolower($1) == "etag:" { print $2 }')
```

Without `If-Match` the write answers `428`. If the rules changed since your read it answers `412 REVISION_MISMATCH` and writes nothing: read again, then send the change. Each write answers a new `ETag` to use on your next one.

### List the rules

[`GET /v2/cdn/cache/{domain_public_id}/rules/` in the API reference](https://docs.diamwall.com/api/#tag/cache/GET/v2/cdn/cache/{domain_public_id}/rules/)

```bash
curl "$CACHE/rules/?limit=50" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY"
```

```json
{
  "revision": "sha256:49976d9020e8...",
  "data": {
    "items": [
      {
        "id": "r_00000000000000000000000000000002",
        "name": "Never cache the API",
        "description": "",
        "enabled": true,
        "priority": 10,
        "type": "filter",
        "expressions": [
          { "type": "main", "field": "hostname", "operator": "equals", "value": "api.example.com" },
          { "type": "or", "field": "uri", "operator": "starts_with", "value": "/api/" }
        ],
        "action": { "eligibility": "bypass" }
      }
    ],
    "page": { "limit": 50, "next_cursor": null, "total": 1 }
  }
}
```

- `limit` goes from 1 to 100. Without it a page holds 50 rules.
- To read the next page, send `data.page.next_cursor` back as `cursor`, until it is `null`.
- `cursor` and `limit` are the only query parameters. Any other answers `400 INVALID_REQUEST`.
- If the rules change between two pages, the next page answers `409 CURSOR_STALE`. Start again from the first page.
- An empty `items` means the domain has no cache rule.
- A value the API does not offer is answered as `other`. An action with `other` in it cannot be sent back as it is.

### Read one rule

[`GET /v2/cdn/cache/{domain_public_id}/rules/{rule_id}/` in the API reference](https://docs.diamwall.com/api/#tag/cache/GET/v2/cdn/cache/{domain_public_id}/rules/{rule_id}/)

```bash
curl "$CACHE/rules/r_00000000000000000000000000000001/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY"
```

The rule is under `data`, with its whole `action`. The `ETag` is the same revision the list gives. An id that no rule has answers `404 RESOURCE_ITEM_NOT_FOUND`.

### Create a rule

[`POST /v2/cdn/cache/{domain_public_id}/rules/` in the API reference](https://docs.diamwall.com/api/#tag/cache/POST/v2/cdn/cache/{domain_public_id}/rules/)

Read the list first to get the `ETag`. A domain with no rules has one too.

**Cache a section**

```bash
curl -X POST "$CACHE/rules/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "If-Match: $ETAG" \
  -d '{
    "name": "Cache the blog",
    "description": "Public pages of the blog",
    "enabled": true,
    "priority": 10,
    "type": "filter",
    "expressions": [
      { "type": "main", "field": "uri", "operator": "starts_with", "value": "/blog/" }
    ],
    "action": {
      "eligibility": "cache",
      "runtime_version": 2,
      "edge_ttl": "1h",
      "min_uses": 1,
      "cache_retention": "90d",
      "cache_statuses": [200, 301, 302, 404],
      "revalidate": true,
      "stale_while_offline": true,
      "stale_while_revalidating": true
    }
  }'
```

**Bypass**

```bash
curl -X POST "$CACHE/rules/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "If-Match: $ETAG" \
  -d '{
    "name": "Never cache the API",
    "enabled": true,
    "type": "filter",
    "expressions": [
      { "type": "main", "field": "hostname", "operator": "equals", "value": "api.example.com" },
      { "type": "or", "field": "uri", "operator": "starts_with", "value": "/api/" }
    ],
    "action": { "eligibility": "bypass" }
  }'
```

**Every request**

```bash
curl -X POST "$CACHE/rules/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "If-Match: $ETAG" \
  -d '{
    "name": "Cache public assets",
    "enabled": true,
    "type": "all",
    "action": {
      "eligibility": "cache",
      "edge_ttl": "30m",
      "browser_ttl": "1h",
      "query_string": "ignore_all",
      "strip_cookies": true
    }
  }'
```

The answer is `201` with the new rule under `data`, its `id` included, and a new `ETag` header.

The rule is stored as you send it. The API adds no default, no `priority` and no `runtime_version`. Nothing is trimmed or repaired, and an unknown field is refused.

> **Not every option is available on every domain**
> A rule that asks for something the domain does not have yet answers `409 CACHE_POLICY_RUNTIME_UNAVAILABLE` (the version 2 options, a TTL of `5m` included) or `409 CACHE_AUTHENTICATED_FALLBACK_UNAVAILABLE` (`authenticated_fallback: true`). Sending it again answers the same. Read the [rule options](#rule-options) first to see what is available.

### Change a rule

[`PATCH /v2/cdn/cache/{domain_public_id}/rules/{rule_id}/` in the API reference](https://docs.diamwall.com/api/#tag/cache/PATCH/v2/cdn/cache/{domain_public_id}/rules/{rule_id}/)

Send only the fields that change. A field you leave out keeps its value.

```bash
curl -X PATCH "$CACHE/rules/r_00000000000000000000000000000001/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "If-Match: $ETAG" \
  -d '{ "enabled": false }'
```

The answer is the rule after the edit, under `data`. An empty body, `{}`, answers `400 NO_CHANGES`.

> **action is replaced whole**
> - When you send `action`, it takes the place of the one the rule has. A field you leave out of it is removed from the rule.
> - To change one field of an action, read the rule, change that field, and send every field the action is to keep, `runtime_version`, `cache_key` and `auth_cookies` included.
> - To switch a boolean of an action off, send it as `false` in the whole action.
> - To change only the name, description, priority or `enabled`, leave `action` out of the body.
> - `expressions` is replaced whole too.

### Delete a rule

[`DELETE /v2/cdn/cache/{domain_public_id}/rules/{rule_id}/` in the API reference](https://docs.diamwall.com/api/#tag/cache/DELETE/v2/cdn/cache/{domain_public_id}/rules/{rule_id}/)

```bash
curl -X DELETE "$CACHE/rules/r_00000000000000000000000000000001/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  -H "If-Match: $ETAG"
```

The request has no body. The answer has no rule: `operation.id` is the id that was deleted, and the `ETag` header is the new revision. An id that is already gone answers `404 RESOURCE_ITEM_NOT_FOUND` or `404 RULE_NOT_FOUND`.

### Reorder the rules

[`PUT /v2/cdn/cache/{domain_public_id}/rules/order/` in the API reference](https://docs.diamwall.com/api/#tag/cache/PUT/v2/cdn/cache/{domain_public_id}/rules/order/)

Send every rule id in `ids`, in the order the rules are to have. It is the whole order, never only the rules that moved. Read every page of the list first.

```bash
curl -X PUT "$CACHE/rules/order/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "If-Match: $ETAG" \
  -d '{
    "ids": [
      "r_00000000000000000000000000000002",
      "r_00000000000000000000000000000001"
    ]
  }'
```

The answer is all the rules in their new order, under `data.items`, with no paging. A list that leaves a rule out, names a rule that does not exist or has an id twice answers `400 INVALID_REQUEST`. A reorder changes nothing else in a rule.

### When a write gives no clear answer

`502 FILE_SERVER_OUTCOME_UNKNOWN` and `FILE_SERVER_V2_ERROR` mean the write may have been made. Do not send it again as it is. Read the rules, compare them with what you meant to write, and only then send a change with the new `ETag`. After a create, the rule may already be in the list.

## Rule options

[`GET /v2/cdn/cache/{domain_public_id}/references/cache-rule-options/` in the API reference](https://docs.diamwall.com/api/#tag/cache/GET/v2/cdn/cache/{domain_public_id}/references/cache-rule-options/)

This read tells you what a cache rule can use on the domain, and the defaults that apply when no matching rule sets a value. Read it before you build or show a rule form.

```bash
curl "$CACHE/references/cache-rule-options/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY"
```

```json
{
  "revision": "sha256:f3be288d25e7...",
  "consistency": "verified",
  "runtime_version": 2,
  "capabilities": {
    "policy_v2": true,
    "authenticated_fallback": true,
    "continuity": true
  },
  "defaults": {
    "origin_cache_control": { "state": "resolved", "value": "respect" },
    "min_uses": { "state": "resolved", "value": 3 },
    "cache_retention": { "state": "resolved", "value": "1d" },
    "cache_statuses": { "state": "resolved", "value": [200] },
    "query_string": { "state": "resolved", "value": "standard" },
    "edge_ttl": { "state": "resolved", "value": "respect_origin" }
  },
  "choices": {},
  "semantics": {}
}
```

The answer is one object, not a list. It takes no `cursor` and no `limit`, and has no `ETag`.

| `capabilities` | When it is `false` |
| --- | --- |
| `policy_v2` | Do not create new rules with `runtime_version: 2` |
| `authenticated_fallback` | Do not send `authenticated_fallback: true` |
| `continuity` | Do not offer Continuity |

A `false` never means you should delete a rule that is already saved.

About `defaults`:

- Use `value` only when `state` is `resolved`. With `unknown`, `value` is `null`: treat the default as unavailable and do not guess one.
- A default is for display. Do not copy it into a rule.
- `origin_cache_control` can have the value `partial`, with `ignored_headers` and `respected_headers`. It describes a default that ignores some origin headers and respects others. It is never a value to send in a rule.
- A default that is missing from the answer was not answered. Do not fill it in.

## Cache settings

The settings are the cache configuration of the domain as a whole. Cache rules are not part of them.

### Read the settings

[`GET /v2/cdn/cache/{domain_public_id}/settings/cache/` in the API reference](https://docs.diamwall.com/api/#tag/cache/GET/v2/cdn/cache/{domain_public_id}/settings/cache/)

```bash
curl "$CACHE/settings/cache/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY"
```

```json
{
  "revision": "sha256:8c2ebd6d17a1...",
  "consistency": "verified",
  "data": {
    "configuration": {
      "state": "resolved",
      "value": {
        "cache_enabled": true,
        "smart_cache": true,
        "stale_while_offline": false,
        "stale_while_revalidating": false,
        "cache_error_responses": false,
        "strip_response_cookies": false,
        "follow_redirects": false,
        "request_coalescing": true,
        "edge_ttl": "1d",
        "browser_ttl": "match_edge",
        "query_string": "standard",
        "static_content": {
          "images": { "enabled": true, "extensions": ["jpg", "jpeg", "gif", "png", "ico", "webp", "avif", "svg"] },
          "assets": { "enabled": false, "extensions": ["js", "css"] },
          "fonts": { "enabled": false, "extensions": ["woff", "woff2", "ttf", "eot", "otf"] }
        },
        "vary": { "webp": false, "avif": false, "hostname": false, "country": false, "mobile": false }
      },
      "updated": "2026-10-10T12:00:00.000Z"
    }
  }
}
```

`static_content` has seven types: `images`, `assets`, `fonts`, `media`, `feed`, `documents` and `archives`. The example shows three.

- Use `value` only when `state` is `resolved`. A `state` of `unknown` means the configuration is unavailable. It is not a cache that is off, and there is no `ETag` to write with.
- A field that is missing was not answered. A missing boolean is not `false`.
- `edge_ttl`, `browser_ttl` or `query_string` can be answered as `other` when the domain holds a value outside the lists below. An edit can only set a value from the lists.
- `updated` is the UTC time of the last change. It is read-only.
- Keep the `ETag` header. An edit needs it.

### Change the settings

[`PATCH /v2/cdn/cache/{domain_public_id}/settings/cache/` in the API reference](https://docs.diamwall.com/api/#tag/cache/PATCH/v2/cdn/cache/{domain_public_id}/settings/cache/)

Read the settings to get their `ETag`, then send only the fields that change. This `ETag` is not the one of the cache rules.

```bash
SETTINGS_ETAG=$(curl -s -o /dev/null -D - "$CACHE/settings/cache/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  | tr -d '\r' | awk 'tolower($1) == "etag:" { print $2 }')

curl -X PATCH "$CACHE/settings/cache/" \
  -H "Authorization: Api-Key $DIAMWALL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "If-Match: $SETTINGS_ETAG" \
  -d '{
    "smart_cache": false,
    "browser_ttl": "90d",
    "query_string": "ignore_all",
    "vary": { "webp": true, "avif": true }
  }'
```

The answer is the settings after the edit, in the same form as the read, with a new `ETag`.

| Field | Allowed values |
| --- | --- |
| `cache_enabled` | `true` switches the cache of the domain on, `false` off |
| `smart_cache` | `true` or `false` |
| `stale_while_offline` | `true` serves a stale copy while the origin does not answer |
| `stale_while_revalidating` | `true` serves a stale copy while a fresh one is fetched |
| `cache_error_responses` | `true` caches the error answers of the origin |
| `strip_response_cookies` | `true` removes the cookies of an answer before it is cached |
| `follow_redirects` | `true` follows a redirect of the origin and caches what it leads to |
| `request_coalescing` | `true` makes requests for the same uncached content wait for one fetch |
| `edge_ttl` | `respect_origin`, `30m`, `1h`, `4h`, `12h`, `1d`, `7d`, `30d`, `90d`, `1y` |
| `browser_ttl` | `match_edge`, `30m`, `1h`, `4h`, `12h`, `1d`, `7d`, `30d`, `90d`, `1y` |
| `query_string` | `standard`, `sort`, `ignore_all` |
| `static_content` | For each type, `enabled`, `extensions` or both |
| `vary` | `webp`, `avif`, `hostname`, `country`, `mobile`: `true` keeps a separate copy for each |

- Booleans are JSON booleans. `"true"`, `1` and `null` are refused.
- `extensions` replaces the whole list of its type. Each entry is 1 to 16 lower case letters and digits with no dot, such as `jpg` or `woff2`. A list holds at most 128, none twice.
- `5m` and `60d` exist for cache rules, not for these settings.
- An empty body, `{}`, answers `400 NO_CHANGES`.

> **Edge TTL and cache rules**
> Each active cache rule has to keep its copies for longer than the Edge TTL. A change of `edge_ttl` that breaks this for a rule is refused with `400 INVALID_REQUEST` naming `edge_ttl`. Correct the cache rule, or choose another Edge TTL. Edits that leave `edge_ttl` alone are not affected.

## Limits and permissions

- **Credits.** Each domain has a budget of 3000 credits a minute, shared by everyone who calls the API for that domain. Reading the rules costs 6 credits. Reading the rule options or the settings, and every write of a rule or of the settings, costs 8. A purge costs 30.
- **Refused early.** A request the API refuses by itself, such as a `400` for a wrong field or a `428`, spends no credits of the domain.
- **Out of credits.** The call answers `429 TOO_MANY_REQUESTS`, with the wait in `details.retry_after_seconds` and in the `Retry-After` header.
- **Rule limit.** A domain holds at most 500 cache rules. A create beyond that answers `400 INVALID_REQUEST` with a `request_id`.
- **Permissions.** Reads need `speed.view` on the domain. Creating a rule needs `speed.create`. Deleting a rule needs `speed.delete`. Editing or reordering rules, changing the settings and purging need `speed.edit`, and `speed.create` or `speed.delete` also allow them.

## Errors you are likely to see

| Status | Code | Where | What happened |
| --- | --- | --- | --- |
| `400` | `INVALID_REQUEST` | All | A field is wrong. The answer names it in `fields` when it can. |
| `400` | `NO_CHANGES` | Rule edit, settings edit | An edit was sent with nothing to change. |
| `400` | `IDEMPOTENCY_KEY_REQUIRED`, `INVALID_IDEMPOTENCY_KEY` | Purge | The `Idempotency-Key` header is missing or not in its form. |
| `400` | `INVALID_PRECONDITION` | Writes | `If-Match` is not one quoted `ETag` as a read gave it. |
| `404` | `RESOURCE_ITEM_NOT_FOUND`, `RULE_NOT_FOUND` | Rules | No rule has that id. It may have been deleted. Read the list again. |
| `409` | `CURSOR_STALE` | Rule list | The rules changed while you were paging. Start from the first page. |
| `409` | `RULE_NAME_CONFLICT` | Rule create, edit | Another rule has that name. |
| `409` | `CACHE_POLICY_RUNTIME_UNAVAILABLE` | Rule create, edit | The rule asks for version 2 options that are not available on the domain. |
| `409` | `CACHE_AUTHENTICATED_FALLBACK_UNAVAILABLE` | Rule create, edit | `authenticated_fallback: true` is not available on the domain. |
| `409` | `CACHE_RULES_TRANSACTION_PENDING` | Rule writes, settings edit | A change of the cache rules is still pending. Read the rules again, then send the change with the new `ETag`. |
| `409` | `LEGACY_COLLECTION_DRIFT` | Rules | The rules of the domain are stored in an older form that cannot be verified. Nothing in the request can fix it. |
| `409` | `INVALID_STATE` | Settings edit | The change was refused for the state of the settings or of the domain. |
| `409` | `IDEMPOTENCY_CONFLICT`, `ACTION_OUTCOME_UNKNOWN` | Purge | See [The Idempotency-Key](#the-idempotency-key). Stop, and do not retry. |
| `412` | `REVISION_MISMATCH` | Writes | What you are writing changed since your read. Read again and retry. |
| `428` | `PRECONDITION_REQUIRED` | Writes | The `If-Match` header is missing. |
| `429` | `TOO_MANY_REQUESTS` | All | The domain is out of credits for now. |
| `429` | `ACTION_HISTORY_FULL` | Purge | No more runs of the purge are kept for the domain. Waiting does not end it. Do not retry. |
| `502` | `FILE_SERVER_OUTCOME_UNKNOWN` | Writes, purge | The answer was lost and the change may have been made. |
| `503` | `ACTION_UNAVAILABLE` | Purge | The cache servers could not be reached. |
| `503` | `CACHE_RULE_OPTIONS_UNAVAILABLE` | Rule options | The options could not be read. Try again later. |
| `503` | `PUBLICATION_FAILED` | Settings edit | The change could not be published and verified. Read the settings again before another attempt. |

The errors that come from the key itself, such as `API_KEY_IP_NOT_ALLOWED`, are on the [Errors](https://docs.diamwall.com/reference/errors/) page.

## All Cache endpoints

Each row opens the endpoint in the API reference, with every parameter, rule and response.

See the [API reference](https://docs.diamwall.com/api/#tag/cache) for every endpoint, with parameters and responses.
