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

# Caching

> Configure in-memory or Redis query caching, TTL, and Cache-Control in OpenReader.

The GraphQL API server provided by `@subsquid/graphql-server` supports caching via additional flags. It is done on a per-query basis. The whole response is cached for a specified amount of time (`maxAge`).

Caching is disabled until `--dumb-cache` is set. When caching is enabled and the numeric flags are omitted, `squid-graphql-server` uses these defaults:

| Flag                   |   Default | Applies to                 |
| ---------------------- | --------: | -------------------------- |
| `--dumb-cache-max-age` | `5000` ms | In-memory and Redis caches |
| `--dumb-cache-ttl`     | `5000` ms | In-memory cache only       |
| `--dumb-cache-size`    |   `50` MB | In-memory cache only       |

To enable caching when deploying to SQD Cloud, add the caching flags to the `serve:prod` command definition at [`commands.json`](/en/cloud/reference/cli/commands-json), then use that command to run the server in the [deployment manifest](/en/cloud/reference/manifest#deploy). Cloud currently supports only in-memory cache.

For example, the snippets below deploy a GraphQL API server with a `100 MB` in-memory cache, a `5` second entry TTL, and a `5` second response max age:

```json commands.json theme={"system"}
{
  // ...
  "serve:prod": {
    "description": "Start the GraphQL API server with caching and limits",
    "cmd": [
      "squid-graphql-server",
      "--dumb-cache",
      "in-memory",
      "--dumb-cache-ttl",
      "5000",
      "--dumb-cache-size",
      "100",
      "--dumb-cache-max-age",
      "5000"
    ]
  }
  // ...
}
```

```yaml squid.yaml theme={"system"}
# ...
deploy:
  # other services ...
  api:
    cmd: ["sqd", "serve:prod"]
```

The complete flag list and current defaults are available through `npx squid-graphql-server --help`.

## `--dumb-cache <cache-type>`

Enables caching with either `in-memory` or `redis`. For `redis`, set the Redis connection string in `REDIS_URL`. SQD Cloud deployments currently support only `in-memory` cache.

## `--dumb-cache-size <mb>`

Maximum cache size in megabytes. Applies only to the in-memory cache. Default: `50`.

## `--dumb-cache-max-age <ms>`

Global response max age in milliseconds. It is passed to both cache implementations and controls the cache response max age. Default: `5000`.

## `--dumb-cache-ttl <ms>`

Time-to-live for in-memory cache entries. Entries become eligible for eviction when they have not been updated for this duration. Default: `5000`.
