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
Replace your Sanity client in the Next.js application
Instead of using the Sanity client directly, use the one provided by
defineLiveas described in the next-sanity package. This will automatically add cache tags to all queries.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.
Are you using cacheComponents and next-sanity/experimental/live?
You might have to replace the tag prefix sanity: with sp: in the cache-expiration route.Add a purger
Add a purger in Purge Patrol to automatically send a request to your cache-expiration route when content changes.