# The cache tags invalidation webhook

Once your pages carry cache tags, you need a way to invalidate them when editors change content. In implementing a caching mechanism, this is traditionally the most complex step to tackle.

Fortunately, DatoCMS handles the complex job of tracking every possible alteration in your schema, text, images, and videos for you. When any change happens, DatoCMS can immediately send a list of tags that need invalidation to your frontend through a single webhook.

## Setting up the webhook

Within your Project Settings, create a new webhook. Choose the "Invalidate" event of the "Content Delivery API Cache Tags" entity as the trigger:

(Video content)

The requests that the webhook will send will be in this JSON format:

```json
POST /your/invalidation/endpoint HTTP/1.1
Content-Type: application/json

{
  "entity_type": "cda_cache_tags",
  "event_type": "invalidate",
  "entity": {
    "id": "cda_cache_tags",
    "type": "cda_cache_tags",
    "attributes": {
      "tags": ["N*r;L", "6-KZ@", "t#k[uP"]
    }
  },
  "related_entities": []
}
```

> [!WARNING] Invalidation batches can be large
> DatoCMS groups invalidations over a short window, so the `tags` array has no fixed upper bound: a bulk publish can easily produce several hundred tags in a single delivery.
> 
> Most purge APIs cap how many tags one request may carry, and rate-limit how often you can call them. Chunk the array to your provider's per-request limit, and retry on rate-limit responses. For reference, Cloudflare accepts 100 tags per purge request on Business plans.

## Implementing the endpoint

The final step is to implement the endpoint that will receive incoming requests from the webhook. The task of this endpoint will be to execute cache invalidation based on the received cache tags.

The way you perform cache invalidation through tags **greatly depends on the frontend framework and hosting solution you use**. In some instances it's an API call, whereas some frameworks offer specific helper functions. The integration guides cover both cases with working code.

###### Don't forget to invalidate on deploy

When there's a cache layer above your application, content changes are not the only reason a cached page can go stale: a new version of your application will produce different HTML for the same content. Deploys are far less frequent than content changes, so a full purge of the CDN cache as the last step of your deploy pipeline is usually all you need.

## Related content in "Content Delivery API"

- [Content Delivery API Overview](https://www.datocms.com/docs/content-delivery-api.md)
- [Using the JavaScript CDA client](https://www.datocms.com/docs/content-delivery-api/your-first-request.md)
- [Authentication and permissions](https://www.datocms.com/docs/content-delivery-api/authentication.md)
- [Configuring requests: envs, drafts, strict mode, cache tags, etc.](https://www.datocms.com/docs/content-delivery-api/api-endpoints.md)
- [How to fetch records](https://www.datocms.com/docs/content-delivery-api/how-to-fetch-records.md)
- [Filtering records](https://www.datocms.com/docs/content-delivery-api/filtering-records.md)
- [Deep Filtering](https://www.datocms.com/docs/content-delivery-api/deep-filtering.md)
- [Ordering records](https://www.datocms.com/docs/content-delivery-api/ordering-records.md)
- [Pagination](https://www.datocms.com/docs/content-delivery-api/pagination.md)
- [Localization](https://www.datocms.com/docs/content-delivery-api/localization.md)
- [Direct vs. Inverse relationships](https://www.datocms.com/docs/content-delivery-api/inverse-relationships.md)
- [Hierarchical sorting (Tree-like collections)](https://www.datocms.com/docs/content-delivery-api/hierarchical-sorting.md)
- [Modular content fields](https://www.datocms.com/docs/content-delivery-api/modular-content-fields.md)
- [Structured text fields](https://www.datocms.com/docs/content-delivery-api/structured-text-fields.md)
- [Images and videos](https://www.datocms.com/docs/content-delivery-api/images-and-videos.md)
- [Filtering uploads](https://www.datocms.com/docs/content-delivery-api/filtering-uploads.md)
- [SEO and favicon fields](https://www.datocms.com/docs/content-delivery-api/seo-and-favicon.md)
- [Meta fields](https://www.datocms.com/docs/content-delivery-api/meta-fields.md)
- [Cache Tags Overview](https://www.datocms.com/docs/content-delivery-api/cache-tags.md)
- [Cache tags in CDA responses](https://www.datocms.com/docs/content-delivery-api/cache-tags-format.md)
- [The cache tags invalidation webhook](https://www.datocms.com/docs/content-delivery-api/cache-tags-invalidation.md)
- [Integrating cache tags in your project](https://www.datocms.com/docs/content-delivery-api/cache-tags-integrations.md)
- [Error codes & handling failures (CDA)](https://www.datocms.com/docs/content-delivery-api/errors.md)
- [CDA Technical Limits & Rate Limits](https://www.datocms.com/docs/content-delivery-api/technical-limits.md)
- [Complexity](https://www.datocms.com/docs/content-delivery-api/complexity.md)
- [Custom Scalar Types](https://www.datocms.com/docs/content-delivery-api/custom-scalar-types.md)
- [Changelog](https://www.datocms.com/docs/content-delivery-api/changelog.md)