---
description:
  Add HTTP caching to your GraphQL Mesh gateway using `@graphql-mesh/plugin-http-cache`. Reduce
  network traffic and enable conditional caching. Get started now!
---

import { Callout } from '@theguild/components'

# Caching in HTTP

Usually server environments don't have browser's HTTP caching logic. This plugin brings
[HTTP Caching](https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching) to your GraphQL Mesh
gateway.

<Callout>
  The defined cache storage will be used for this plugin. By default, GraphQL Mesh uses
  [LocalForage](/docs/cache/localforage) as a cache storage. For example, you need to follow this
  section to configure [Redis](/docs/cache/redis) as your cache storage. You can find other options
  under the same category.
</Callout>

## Getting Started

```sh npm2yarn
npm i @graphql-mesh/plugin-http-cache
```

Then add the plugin to your configuration;

```yaml filename=".meshrc.yaml"
plugins:
  httpCache: {}
```

## Conditional Caching

You can cache specific URL patterns by using `matches` and `ignores` options.

It follows the WHATWG URLPattern spec. You can find more information about the spec
[here](https://developer.mozilla.org/en-US/docs/Web/API/URLPattern/URLPattern#examples)

```yaml filename=".meshrc.yaml"
plugins:
  httpCache:
    matches:
      - 'https://*.github.com'
      # or you can use objects to match more specific patterns
      - hostname: '*.github.com'
    ignores:
      - 'https://api.github.com/graphql'
      # or
      - hostname: 'api.github.com'
        pathname: '/graphql'
```
