- Home
- Skills
- Frontend & Web Apps
- Next Cache Mutation Gate
Next Cache Mutation Gate
Stop stale UIs and cross-user cache leaks after Next.js mutations.
$9
Works with the AI Agents you already use
Next Cache Mutation Gate
Example session with this skill installed
Audit my updateOrgName Server Action. It updates the DB but the dashboard header still shows the old name until I refresh the whole page. How do I fix the stale cache?
- Read your context and instructions
- Compiled the next cache mutation
I have audited the updateOrgName action and the dashboard rendering logic. The stale state is caused by a missing invalidation call in the Server Action and a lack of specific tags in the cached query.
Cache inventory
getOrgData:unstable_cache| tags:['org-data']| Shared across all orgs (Risk).updateOrgName: Server Action | Write:db.org.update| No revalidation found.
Audit Findings and Patch
| Component | Finding | Severity | Evidence |
|---|---|---|---|
| Mutation Invalidate | Missing revalidateTag | Major | Action completes but getOrgData cache remains hit. |
| Cache Key Scope | Global tag used for tenant data | Blocker | revalidateTag('org-data') would purge all orgs. |
Hardening Patch
// 1. Define granular tags
export const tags = {
orgData: (orgId: string) => `org:${orgId}:data`,
} as const;
// 2. Update cached read
export function getOrgData(orgId: string) {
return unstable_cache(
async () => db.org.findUnique({ where: { id: orgId } }),
[`org-data-${orgId}`],
{ tags: [tags.orgData(orgId)] }
)();
}
// 3. Fix the mutation
export async function updateOrgName(orgId: string, name: string) {
const user = await auth();
if (!user) throw new Error("Unauthorized");
await db.org.update({ where: { id: orgId }, data: { name } });
// Invalidate specific tenant tag
revalidateTag(tags.orgData(orgId));
}
Residual risks
Client Cache: Ensure the frontend calls router.refresh() if the layout doesn't automatically reflect the RSC change.
- Edge Lag: If using a multi-region database, the revalidation might fire before the replica is consistent.
Next steps
- Move tag definitions to a centralized
lib/cache-tags.ts. - Update the dashboard layout to use the new
getOrgData(orgId)function. - Verify that updating Org A does not trigger a cache miss for Org B.
Connects securely to your tools. The creator never sees your data.
About this skill
Stop stale UIs and cross-user cache leaks after Next.js mutations. Audits App Router Data Cache, Full Route Cache, and unstable_cache around writes. Returns Cache inventory, Gate findings, Hardening patch, and Residual risks. Covers missing revalidateTag/Path, personalized data cached globally, and weak cache keys. Includes checklist, patterns, anti-patterns, and a bad-to-good profile update example. Complements Server Action AuthZ and Zod Contract Sync; does not replace authorization.
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Frontend & Web Apps.
Focuses on Next.js server-side caching. Does not replace authorization logic. Does not manage external CDN purges or browser-level caching.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed 21 days ago