Sanity Studio Cache Actions
This guide explains how to use the custom cache management and deployment actions directly from Sanity Studio.
For a dedicated UI tool that clears cache from multiple sources (Next.js, Vercel, Redis/Upstash), see the Cache Clear Tool. This page covers document-level actions that appear in the document menu.
Overview
The Sanity Studio has been enhanced with custom document actions that allow you to:
- Clear Cache - Clear all cached content
- Clear Cache for Document Type - Clear cache for a specific content type
- Trigger Redeploy - Trigger a Vercel redeployment
- Clear Cache & Redeploy - Combined action for both
These actions appear in the document actions menu (three dots menu) in Sanity Studio.
Setup
1. Environment Variables
Add these to your .env.local file (or Vercel environment variables):
# Required for cache actions
SANITY_STUDIO_SITE_URL=https://your-domain.com
SANITY_STUDIO_CACHE_AUTH_TOKEN=your-secret-token-here
# Optional: For redeploy actions
SANITY_STUDIO_VERCEL_DEPLOY_HOOK=https://api.vercel.com/v1/integrations/deploy/...
# OR
SANITY_STUDIO_VERCEL_TOKEN=your-vercel-token
SANITY_STUDIO_VERCEL_PROJECT_ID=your-project-id
2. Get Vercel Deploy Hook (Optional)
If you want to trigger redeployments from Sanity:
- Go to your Vercel Project Dashboard
- Navigate to Settings → Git → Deploy Hooks
- Click "Create Hook"
- Name it: "Sanity Studio Deploy"
- Copy the hook URL
- Add to environment variables as
SANITY_STUDIO_VERCEL_DEPLOY_HOOK
Alternative: Use Vercel API token:
- Go to https://vercel.com/account/tokens
- Create a new token
- Get your project ID from Vercel dashboard
- Add
SANITY_STUDIO_VERCEL_TOKENandSANITY_STUDIO_VERCEL_PROJECT_ID
Usage
From Sanity Studio
- Open any document in Sanity Studio
- Click the three dots menu (⋮) in the top right
- Select an action:
- "Clear Cache" - Clears all cached content
- "Clear Cache for This Type" - Clears cache only for this document type
- "Trigger Redeploy" - Triggers a Vercel redeployment
- "Clear Cache & Redeploy" - Does both actions
Actions Explained
Clear Cache
- Clears all cached content across all locales
- Useful when you've made multiple content changes
- Takes effect immediately
Clear Cache for This Type
- Clears cache only for the specific document type (e.g., "hero", "service")
- More targeted - only affects related content
- Faster than clearing everything
Trigger Redeploy
- Triggers a new Vercel deployment
- Useful when you want to rebuild the site with latest changes
- Check Vercel dashboard for deployment status
Clear Cache & Redeploy
- Combines both actions
- Clears cache first, then triggers redeploy
- Best for major content updates
Configuration
For Local Development
Add to studio/.env.local:
SANITY_STUDIO_SITE_URL=http://localhost:3000
SANITY_STUDIO_CACHE_AUTH_TOKEN=your-local-token
For Production
Add to Vercel Environment Variables:
- Go to Project Settings → Environment Variables
- Add variables for Production, Preview, and Development
- Make sure
SANITY_STUDIO_SITE_URLpoints to your production URL
Troubleshooting
"Site URL not configured"
Solution: Set SANITY_STUDIO_SITE_URL in your environment variables.
"Failed to clear cache"
Possible causes:
SANITY_STUDIO_CACHE_AUTH_TOKENdoesn't matchCACHE_AUTH_TOKENin your Next.js app- Site URL is incorrect
- API endpoint is not accessible
Solution:
- Verify both tokens match
- Check site URL is correct
- Test API endpoint manually:
curl -X POST https://your-domain.com/api/cache/clear?all=true -H "Authorization: Bearer your-token"
"Deploy hook not configured"
Solution:
- Set up Vercel Deploy Hook (see setup instructions above)
- Or configure Vercel API token + project ID
Actions not appearing in menu
Solution:
- Restart Sanity Studio:
cd studio && npm run dev - Check browser console for errors
- Verify environment variables are loaded
Security Notes
⚠️ Important Security Considerations:
- Keep tokens secret - Never commit tokens to git
- Use environment variables - Store in Vercel, not in code
- Restrict access - Only authorized users should have access to Sanity Studio
- Use strong tokens - Generate secure random tokens
Best Practices
- Use "Clear Cache for This Type" for single document updates
- Use "Clear Cache" after bulk updates
- Use "Clear Cache & Redeploy" for major content changes
- Monitor cache performance - Check logs to see cache hit rates
- Set up webhooks - For automatic cache invalidation (see Sanity Webhooks)
Integration with Webhooks
These manual actions complement the automatic webhook-based cache invalidation:
- Webhooks - Automatic cache clearing when content is published
- Manual Actions - On-demand cache clearing and redeployment
Use both for maximum flexibility!
Example Workflow
- Edit content in Sanity Studio
- Publish changes
- Click "Clear Cache for This Type" to see changes immediately
- Or wait for automatic webhook to clear cache (if configured)
- Use "Trigger Redeploy" if you need to rebuild the site
Support
For issues:
- Check Caching Overview for cache configuration
- Check Vercel Deployment Guide for deployment setup
- Verify environment variables are set correctly