# Source: https://docs.hypermode.com/dgraph/graphql/query/cached-results.md

# Cached Results

> Cached results can serve read-heavy workloads with complex queries to improve performance. This refers to external caching at the browser/CDN level

<Info>
  We're overhauling Dgraph's docs to make them clearer and more approachable. If
  you notice any issues during this transition or have suggestions, please
  [let us know](https://github.com/hypermodeinc/docs/issues).
</Info>

Cached results can be used to serve read-heavy workloads with complex queries to
improve performance. When cached results are enabled for a query, the stored
results are served if queried within the defined Time to Live (TTL) of the
cached query.

When using cached results, Dgraph adds the appropriate HTTP headers so the
caching can be done at the browser or content delivery network (CDN) level.

<Note>
  Caching refers to external caching at the browser/CDN level. Internal caching
  at the database layer isn't currently supported.
</Note>

### Enabling cached results

To enable the external result cache you need to add the
`@cacheControl(maxAge: int)` directive at the top of your query. This directive
adds the appropriate `Cache-Control` HTTP headers to the response, so that
browsers and CDNs can cache the results.

For example, the following query defines a cache with TTL of 15 seconds.

```graphql
query @cacheControl(maxAge: 15) {
  queryReview(filter: { comment: { alloftext: "Fantastic" } }) {
    comment
    by {
      username
    }
    about {
      name
    }
  }
}
```

Dgraph's returned HTTP headers:

```txt
Cache-Control: public,max-age=15
Vary: Accept-Encoding
```