# Proxy Cache Configuration

The `proxy-cache` plugin caches HTTP responses in memory or on disk to reduce upstream traffic and supports conditional caching and cache purging.<!-- --> <!-- -->Configuration covers static settings and plugin parameters.

## Static Configurations[​](#static-configurations "Direct link to Static Configurations")

The default gateway configuration includes proxy cache settings for disk caching and cache zones. The file to update depends on how the gateway is deployed:

* Host or Docker
* Kubernetes (Helm)

For host or Docker deployments, configure the following settings:

config.yaml

```
apisix:

  proxy_cache:

    cache_ttl: 10s  # default cache TTL used when caching on disk, only if none of the `Expires`

                    # and `Cache-Control` response headers is present, or if the gateway returns

                    # `502 Bad Gateway` or `504 Gateway Timeout` due to unavailable upstreams

    zones:

      - name: disk_cache_one

        memory_size: 50m

        disk_size: 1G

        disk_path: /tmp/disk_cache_one

        cache_levels: 1:2

      # - name: disk_cache_two

      #   memory_size: 50m

      #   disk_size: 1G

      #   disk_path: "/tmp/disk_cache_two"

      #   cache_levels: "1:2"

      - name: memory_cache

        memory_size: 50m
```

Reload or restart the gateway for the changes to take effect.

In the APISIX Helm chart version `2.16.0` or later and the API7 Gateway Helm chart version `3.10.3` or later, set `apisix.proxyCache`.

Each chart renders this value as `apisix.proxy_cache` in the gateway configuration:

values.yaml

```
apisix:

  proxyCache:

    cacheTtl: 10s

    zones:

      - name: disk_cache_one

        memory_size: 50m

        disk_size: 1G

        disk_path: /tmp/disk_cache_one

        cache_levels: 1:2

      - name: memory_cache

        memory_size: 50m
```

Then apply the values file with the chart used for this gateway release:

```
helm upgrade <release-name> <chart-name> -n <namespace> -f values.yaml
```

## Parameters[​](#parameters "Direct link to Parameters")

See plugin [common configurations](https://docs.api7.ai/apisix/reference/plugin-common-configurations.md) for configuration options available to all plugins.

* cache\_strategy

  string

  default: `disk`

  valid value:

  `disk` or `memory`

  ***

  Caching strategy. Cache on disk or in memory.

* cache\_zone

  string

  default: `disk_cache_one`

  ***

  Cache zone used with the caching strategy. The value should match one of the cache zones defined in the [configuration files](https://docs.api7.ai/hub/proxy-cache/configuration.md#static-configurations) and should correspond to the caching strategy. For example, when using the in-memory caching strategy, you should use an in-memory cache zone.

* cache\_key

  array\[string]

  default: `["$host", "$request_uri"]`

  ***

  Values that are concatenated in order to form the cache key.

  Supports [built-in variables](https://docs.api7.ai/apisix/reference/built-in-variables.md) and constant strings. Prefix variables with a `$` sign.

* cache\_bypass

  array\[string]

  ***

  Values that are concatenated in order. If the result is neither empty nor exactly `0`, the response is not retrieved from the cache.

  Supports [built-in variables](https://docs.api7.ai/apisix/reference/built-in-variables.md) and constant strings. Prefix variables with a `$` sign.

* cache\_method

  array\[string]

  default: `["GET", "HEAD"]`

  valid value:

  Any combination of methods from "GET", "POST", and "HEAD"

  ***

  Request methods whose responses can be cached.

* cache\_http\_status

  array\[integer]

  default: `[200, 301, 404]`

  valid value:

  Any combination of integer values from 200 to 599 inclusive

  ***

  Response HTTP status codes that can be cached.

* hide\_cache\_headers

  boolean

  default: `false`

  ***

  If true, hide `Expires` and `Cache-Control` response headers.

* cache\_control

  boolean

  default: `false`

  ***

  If true, the in-memory strategy honors supported request `Cache-Control` directives and derives the cache TTL from the upstream response's `s-maxage`, `max-age`, or `Expires` value. Regardless of this setting, responses containing `Cache-Control: private`, `no-store`, or `no-cache` are not cached in memory.

* no\_cache

  array\[string]

  ***

  Values that are concatenated in order. If the result is neither empty nor exactly `0`, the response is not cached.

  Supports [built-in variables](https://docs.api7.ai/apisix/reference/built-in-variables.md) and constant strings. Prefix variables with a `$` sign.

* cache\_ttl

  integer

  default: `300`

  valid value:

  greater than or equal to 1

  ***

  Cache time to live (TTL) in seconds when caching in memory.

  To adjust the TTL when caching on disk, update `cache_ttl` in the [configuration files](https://docs.api7.ai/hub/proxy-cache/configuration.md#static-configurations). The TTL value is evaluated in conjunction with the values in the response headers [`Cache-Control`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control) and [`Expires`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Expires) received from the upstream service.

* consumer\_isolation

  boolean

  default: `true`

  ***

  If true, prepend the authenticated consumer identity to the effective cache key when the request resolves to a consumer or remote user. This is skipped when `cache_key` already contains an identity-bearing variable such as `$consumer_name`, `$consumer_group_id`, `$remote_user`, or `$http_authorization`. Available in API7 Enterprise from version 3.9.13 and APISIX from version 3.17.0.

  In API7 Gateway, do not use `$consumer_group_id`: the control plane does not assign consumer group IDs, but including the variable still disables automatic consumer isolation.

* cache\_set\_cookie

  boolean

  default: `false`

  ***

  If true, allow the in-memory strategy to cache responses that include a `Set-Cookie` header. By default, such responses are not cached. Available in API7 Enterprise from version 3.9.13 and APISIX from version 3.17.0.

* max\_resp\_body\_size

  integer

  default: `67108864`

  valid value:

  greater than or equal to 1

  ***

  Maximum response body size in bytes buffered by the memory cache strategy. A response that reaches or exceeds this size is streamed to the client without being cached. The chunk that crosses the threshold is buffered before the limit is enforced, so transient memory use can exceed the configured size. This field does not apply to disk caching. Introduced in API7 Enterprise 3.9.17 and 3.10.4, and APISIX 3.18.0.
