# GraphQL Proxy Cache Configuration

The `graphql-proxy-cache` plugin caches GraphQL query responses in memory or on disk to reduce upstream load and supports authenticated cache purging.<!-- --> <!-- -->Configuration covers static settings and plugin parameters.

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

The gateway reads up to 1 MiB of GraphQL request data by default. The gateway default configuration also includes proxy cache settings for disk caching and cache zones. Update these settings for the deployment type:

* Host or Docker
* Kubernetes (Helm)

For host or Docker deployments, configure the following settings:

config.yaml

```
graphql:

  max_size: 1048576



apisix:

  proxy_cache:

    cache_ttl: 10s  # for caching on disk

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

Then reload the gateway for changes to take effect.

The gateway process must be able to create and write the configured `disk_path`. Mount persistent storage at that path if disk cache entries should survive container replacement.

For the APISIX Helm chart version `2.16.0` or later, configure the following values:

values.yaml

```
apisix:

  graphql:

    maxSize: 1048576

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

For the API7 Gateway Helm chart version `3.10.3` or later, configure the following values:

values.yaml

```
graphql:

  maxSize: 1048576

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

Add these settings to the complete, source-controlled values file used by the deployment. Set the release details, including the installed chart and version:

```
export GATEWAY_RELEASE=replace-with-gateway-release-name

export GATEWAY_NAMESPACE=replace-with-gateway-namespace

export GATEWAY_CHART=replace-with-installed-chart-name

export GATEWAY_CHART_VERSION=replace-with-installed-chart-version
```

Apply the complete values file without changing the chart version:

```
helm upgrade "$GATEWAY_RELEASE" "$GATEWAY_CHART" \

  --namespace "$GATEWAY_NAMESPACE" \

  --version "$GATEWAY_CHART_VERSION" \

  -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/graphql-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\_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 [static configurations](https://docs.api7.ai/hub/graphql-proxy-cache/configuration.md#static-configurations). The value is used only when 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) are both absent.

* consumer\_isolation

  boolean

  default: `true`

  ***

  If true, prepend the authenticated consumer identity to the effective cache key when the request resolves to an APISIX consumer or remote user. Arbitrary upstream credentials, such as a forwarded bearer token, are not used as the identity. If a route forwards user-specific credentials without using an APISIX authentication plugin, different users could receive the same cached response. Enable an APISIX authentication plugin or disable caching for that route. Available in API7 Enterprise from version 3.9.13 and APISIX from version 3.17.0.

* 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.
