Contentful Cache Configuration

We recommend using Contentful webhooks to purge the cache and a Stellate configuration with a long cache max age.

Stellate Configuration

import { Config } from 'stellate'

const config: Config = {
  config: {
    // ... other config fields
    rules: [
      {
        types: ['Query'],
        // this rule caches content for 1 year. This is safe as the webhook will
        // purge the cache whenever there is a change in the content.
        maxAge: 31536000,
        swr: 60,
        description: 'Cache everything (default)',
      },
    ],
  },
}

export default config

Contentful Webhook Configuration

  1. Set the URL as a POST request to your stellate Purging URL https://admin.stellate.co/<your_service_name>

  2. Set Triggers as "Trigger for all events"

  3. Generate a Purging token in your Stellate service settings

  4. Set the header stellate-token with the generated token

  5. Add the following custom webhook payload:

{
  "query": "mutation ContentfulWebookPurging {\n_purgeAll\n}",
  "operationName": "ContentfulWebookPurging"
}
Configuring Contentful webhook payload

Enjoy caching!

After both of these steps, your API should be ready and faster than ever. Learn more about our purging API.