---
searchable: false
---

import { Callout } from '@theguild/components'

# Parsing & Validation Caching

By default, Hive Gateway maintains a parsing and validation cache. If requests contain documents
that have been executed before, they will not be parsed and validated again.

Using the parser cache can improve performance up to ~60%, and using the validation cache up to ~50%
(based on benchmarks).

This behavior is built-in and can be optionally disabled using the `parserAndValidationCache`
options:

```ts filename="gateway.config.ts" {4,5}
import { defineConfig } from '@graphql-hive/gateway'

export const gatewayConfig = defineConfig({
  // disable parse and validate caching
  parserAndValidationCache: false
})
```

<Callout>
  Due to the restrictions of the GraphQL execution flow, we cannot use an async cache storage as we
  use in other caching plugins. So the cache storage for the parser and validation cache should be
  synchronous, and it is an in-memory store by default.
</Callout>

Furthermore, you can provide your own cache store to both of these plugins by implementing the
following interface:

```ts
interface CacheStore<T> {
  get(key: string): T | undefined
  set(key: string, value: T): void
}
```

You can then pass your cache store to the `parserAndValidationCache` options:

```ts filename="gateway.config.ts" {9-13}
import { defineConfig } from '@graphql-hive/gateway'

export const gatewayConfig = defineConfig({
  parserAndValidationCache: {
    documentCache: documentCacheStore as CacheStore<DocumentNode>,
    errorCache: errorCacheStore as CacheStore<Error>,
    validationCache: validationCacheStore as CacheStore<typeof validate>
  }
})
```

<Callout>
  We'd recommend to keep the default behavior as-is since it's already optimized for performance.
</Callout>
