> ## Documentation Index
> Fetch the complete documentation index at: https://docs.apinizer.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Update Cache Settings

> Updates cache settings for an API proxy. Cache settings control how API responses are cached and retrieved.

## Endpoint

```
PATCH /apiops/projects/{projectName}/apiProxies/{apiProxyName}/settings/cache/
```

## Authentication

Requires a Personal API Access Token.

### Header

```
Authorization: Bearer YOUR_TOKEN
```

## Request

### Headers

| Header        | Value            | Required |
| ------------- | ---------------- | -------- |
| Authorization | Bearer {token}   | Yes      |
| Content-Type  | application/json | Yes      |

### Path Parameters

| Parameter    | Type   | Required | Description    |
| ------------ | ------ | -------- | -------------- |
| projectName  | string | Yes      | Project name   |
| apiProxyName | string | Yes      | API Proxy name |

### Request Body

#### Full JSON Body Example

```json theme={null}
{
  "cacheSettings": {
    "name": "Cache Settings",
    "description": "Cache configuration",
    "cacheActive": true,
    "cacheOnlyHttpGetRequests": true,
    "cacheKeyType": "QUERY_PARAMS",
    "cacheStorageType": "LOCAL",
    "capacity": 1000,
    "ttl": 3600,
    "handlingAction": "CONTINUE",
    "invalidationRequiresAuthn": false,
    "cacheNullValue": false,
    "variableList": []
  },
  "deploy": false,
  "deployTargetEnvironmentNameList": []
}
```

#### Request Body Fields

| Field                           | Type           | Required | Default | Description                                                        |
| ------------------------------- | -------------- | -------- | ------- | ------------------------------------------------------------------ |
| cacheSettings                   | object         | Yes      | -       | Cache settings object (see fields below)                           |
| deploy                          | boolean        | No       | false   | If true, deploy the API proxy after saving changes                 |
| deployTargetEnvironmentNameList | array\[string] | No       | -       | List of environment names to deploy to (required when deploy=true) |

#### cacheSettings Fields

| Field                     | Type    | Required | Default       | Description                                                     |
| ------------------------- | ------- | -------- | ------------- | --------------------------------------------------------------- |
| name                      | string  | Yes      | -             | Cache settings name                                             |
| description               | string  | No       | -             | Cache settings description                                      |
| cacheActive               | boolean | No       | false         | Enable/disable cache                                            |
| cacheOnlyHttpGetRequests  | boolean | No       | true          | Cache only GET requests (if false, caches all methods)          |
| cacheKeyType              | string  | No       | QUERY\_PARAMS | Cache key type                                                  |
| cacheStorageType          | string  | No       | DISTRIBUTED   | Cache storage type                                              |
| capacity                  | integer | No       | -             | Maximum cache capacity (number of entries)                      |
| ttl                       | integer | No       | -             | Time to live in seconds                                         |
| handlingAction            | string  | Yes      | -             | Cache handling action when cache hit occurs                     |
| invalidationRequiresAuthn | boolean | No       | false         | Require authentication for cache invalidation                   |
| cacheNullValue            | boolean | No       | false         | Cache null/empty responses                                      |
| variableList              | array   | No       | \[]           | List of variables for custom cache key (if cacheKeyType=CUSTOM) |

### EnumCacheKeyType

* `QUERY_PARAMS` - Use query parameters as cache key
* `CUSTOM` - Use custom variables as cache key (requires variableList)

### EnumCacheStorageType

* `LOCAL` - Local cache (per worker instance)
* `DISTRIBUTED` - Distributed cache (shared across all workers)

### EnumCacheHandlingAction

* `CONTINUE` - Return cached response and continue to backend (for logging/monitoring)
* `STOP` - Return cached response and stop (do not call backend)

### Variable Object (for variableList when cacheKeyType=CUSTOM)

```json theme={null}
{
  "name": "userId",
  "type": "HEADER",
  "dataType": "STRING"
}
```

### EnumVariableType

* `HEADER` - Extract from HTTP header
* `PARAMETER` - Extract from query parameter
* `BODY` - Extract from request body
* `CONTEXT_VALUES` - Extract from context values
* `CUSTOM` - Custom variable

### EnumConditionVariableDataType

* `NUMERIC` - Numeric value
* `STRING` - String value
* `DATE` - Date value

## Response

### Success Response (200 OK)

```json theme={null}
{
  "success": true
}
```

When `deploy=true` is specified:

```json theme={null}
{
  "success": true,
  "deploymentResult": {
    "success": true,
    "deploymentResults": [
      {
        "environmentName": "production",
        "success": true,
        "message": "Deployment successful"
      }
    ]
  }
}
```

#### Response Fields

| Field                              | Type    | Description                                               |
| ---------------------------------- | ------- | --------------------------------------------------------- |
| success                            | boolean | Indicates if the request was successful                   |
| deploymentResult                   | object  | Deployment result details (only present when deploy=true) |
| deploymentResult.success           | boolean | Whether the overall deployment was successful             |
| deploymentResult.deploymentResults | array   | List of per-environment deployment results                |

### Error Response (400 Bad Request)

```json theme={null}
{
  "error": "bad_request",
  "error_description": "handlingAction is required"
}
```

#### Common Causes

* Missing required field `handlingAction`
* Invalid enum values
* Invalid cache configuration

### Error Response (401 Unauthorized)

```json theme={null}
{
  "error": "unauthorized_client",
  "error_description": "Invalid token"
}
```

### Error Response (404 Not Found)

```json theme={null}
{
  "error": "not_found",
  "error_description": "ApiProxy (name: MyAPI) was not found!"
}
```

## cURL Example

### Example 1: Basic Cache Configuration

```bash theme={null}
curl -X PATCH \
  "https://demo.apinizer.com/apiops/projects/MyProject/apiProxies/MyAPI/settings/cache/" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "cacheSettings": {
      "name": "Cache Settings",
      "cacheActive": true,
      "cacheOnlyHttpGetRequests": true,
      "cacheKeyType": "QUERY_PARAMS",
      "cacheStorageType": "LOCAL",
      "capacity": 1000,
      "ttl": 3600,
      "handlingAction": "STOP",
      "cacheNullValue": false
    }
  }'
```

### Example 2: Custom Cache Key

```bash theme={null}
curl -X PATCH \
  "https://demo.apinizer.com/apiops/projects/MyProject/apiProxies/MyAPI/settings/cache/" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "cacheSettings": {
      "name": "Cache Settings",
      "cacheActive": true,
      "cacheKeyType": "CUSTOM",
      "cacheStorageType": "DISTRIBUTED",
      "capacity": 5000,
      "ttl": 7200,
      "handlingAction": "CONTINUE",
      "variableList": [
        {
          "name": "userId",
          "type": "HEADER",
          "dataType": "STRING"
        },
        {
          "name": "apiVersion",
          "type": "PARAMETER",
          "dataType": "STRING"
        }
      ]
    }
  }'
```

### Example 3: Save and Deploy

```bash theme={null}
curl -X PATCH \
  "https://demo.apinizer.com/apiops/projects/MyProject/apiProxies/MyAPI/settings/cache/" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "cacheSettings": {
      "name": "Cache Settings",
      "cacheActive": true,
      "cacheOnlyHttpGetRequests": true,
      "cacheKeyType": "QUERY_PARAMS",
      "cacheStorageType": "DISTRIBUTED",
      "capacity": 2000,
      "ttl": 1800,
      "handlingAction": "STOP",
      "cacheNullValue": false
    },
    "deploy": true,
    "deployTargetEnvironmentNameList": ["production"]
  }'
```

## Notes and Warnings

* **handlingAction**: Required field. `CONTINUE` allows backend call for logging, `STOP` prevents backend call
* **Cache Key**: When `cacheKeyType=CUSTOM`, provide `variableList` to define cache key components
* **Storage Type**: `LOCAL` cache is faster but not shared; `DISTRIBUTED` cache is shared across workers
* **TTL**: Cache entries expire after TTL seconds
* **Capacity**: Maximum number of cache entries (older entries are evicted when limit reached)
* **GET Only**: When `cacheOnlyHttpGetRequests=true`, only GET requests are cached (endpoint-level cache can override)
* **Null Values**: When `cacheNullValue=false`, null/empty responses are not cached
* **Deploy**: When `deploy=true`, the API proxy is automatically deployed to the specified environments after saving

## Permissions

User must have **`API_MANAGEMENT` + `MANAGE`** permission in the project.

## Related Documentation

* [Update CORS Settings](/api-reference/api-proxies/settings/update-cors-settings) - Update CORS settings
* [Get API Proxy](/api-reference/api-proxies/crud/get-api-proxy) - Get API proxy details
