How it works

Purge Patrol is a tool that sets up a long-running listener connected to your Sanity.io project. It listens for changes to your content using the Live Content API and sends a request to your Next.js application to expire the cache for the queries that are being used.

Getting started

  1. Replace your Sanity client in the Next.js application

    Instead of using the Sanity client directly, use the one provided by defineLive as described in the next-sanity package. This will automatically add cache tags to all queries.

  2. Set up a cache expiration API route

    Set up a cache expiration API route in your Next.js application to make sure the cache expires. See example below.

  3. Add a purger

    Add a purger in Purge Patrol to automatically trigger cache invalidation when content changes.