pro-laico

payload revalidate

by pro-laico
payload-plugins
Databases & data
v3
^3.0.0
MIT

Overview

Summary generated from the README

Attaches revalidation hooks to every collection and global so a change busts only the cache tags it affects. It also provides finders for use inside 'use cache' getters that fetch and tag in one call. Requires Payload 3, React 19, and Next.js 16+ with Cache Components enabled on the App Router.

Features

  • Auto-attached hooks that bust doc tags and scoped list tags only when declared fields change
  • Join-aware busting of only the affected parent's membership tag
  • Cached finders for docs, ids and globals that fetch and tag in one call
  • Draft saves touch only the draft lane, and context.disableRevalidate is honored
  • Dependency map endpoint showing the reference graph, observed reads and a bust-event log
  • CLI command that renders the cache dependency map as Markdown or JSON

Use cases

  • Avoid purging whole pages when one document changes in a Next.js site backed by Payload
  • Cache Payload reads in use cache getters with precise, id-keyed tags
  • Document which edits trigger which cache invalidations for a team

From the author

Surgical Next.js cache revalidation for Payload CMS: auto-attached hooks that bust exactly the tags a change touches, cached finders that fetch AND tag in one call inside 'use cache' getters, and a dependency map showing what revalidates when.

Installation

npm i @pro-laico/payload-revalidate

18

Stars

1

Forks

1

Open Issues

3 months ago

Last Updated

236

Weekly Downloads

v0.8.5

npm Version

349.3 KB

Unpacked Size

1

Dependencies

Repository stars

18+2 since Sep 7

Show data
Repository stars by day (UTC)
DateStars
Dec 6, 202618
Dec 5, 202618
Dec 4, 202618
Dec 3, 202618
Dec 2, 202618
Dec 1, 202618
Nov 30, 202618
Nov 29, 202618
Nov 28, 202618
Nov 27, 202619
Nov 26, 202619
Nov 25, 202619
Nov 24, 202619
Nov 23, 202619
Nov 22, 202619
Nov 21, 202619
Nov 20, 202619
Nov 19, 202619
Nov 18, 202619
Nov 17, 202618
Nov 16, 202618
Nov 15, 202618
Nov 14, 202618
Nov 13, 202618
Nov 12, 202618
Nov 11, 202618
Nov 10, 202618
Nov 9, 202618
Nov 8, 202618
Nov 7, 202618
Nov 6, 202618
Nov 5, 202618
Nov 4, 202618
Nov 3, 202618
Nov 2, 202618
Nov 1, 202618
Oct 31, 202618
Oct 30, 202618
Oct 29, 202618
Oct 28, 202618
Oct 27, 202618
Oct 26, 202618
Oct 25, 202618
Oct 24, 202618
Oct 23, 202618
Oct 22, 202618
Oct 21, 202617
Oct 20, 202617
Oct 19, 202617
Oct 18, 202617
Oct 17, 202617
Oct 16, 202617
Oct 15, 202617
Oct 14, 202617
Oct 13, 202617
Oct 12, 202617
Oct 11, 202617
Oct 10, 202617
Oct 9, 202617
Oct 8, 202617
Oct 7, 202617
Oct 6, 202617
Oct 5, 202617
Oct 4, 202617
Oct 3, 202617
Oct 2, 202616
Oct 1, 202616
Sep 30, 202616
Sep 29, 202616
Sep 28, 202616
Sep 27, 202616
Sep 26, 202616
Sep 25, 202616
Sep 24, 202616
Sep 23, 202616
Sep 22, 202616
Sep 21, 202616
Sep 20, 202616
Sep 19, 202616
Sep 18, 202616
Sep 17, 202616
Sep 16, 202616
Sep 15, 202616
Sep 14, 202616
Sep 13, 202616
Sep 12, 202616
Sep 11, 202616
Sep 10, 202616
Sep 9, 202616
Sep 8, 202616
Sep 7, 202616

Shared by 7 plugins in pro-laico/payload-plugins.

npm weekly downloads

236+210 since Sep 7

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 6, 2026236
Dec 5, 2026210
Dec 4, 2026202
Dec 3, 2026231
Dec 2, 2026187
Dec 1, 2026232
Nov 30, 2026282
Nov 29, 2026347
Nov 28, 2026506
Nov 27, 2026531
Nov 26, 2026525
Nov 25, 2026486
Nov 24, 2026440
Nov 23, 2026388
Nov 22, 2026331
Nov 21, 2026181
Nov 20, 2026171
Nov 19, 2026128
Nov 18, 2026126
Nov 17, 2026121
Nov 16, 2026126
Nov 15, 2026125
Nov 14, 2026116
Nov 13, 202699
Nov 12, 2026112
Nov 11, 2026116
Nov 10, 2026127
Nov 9, 2026158
Nov 8, 2026219
Nov 7, 2026265
Nov 6, 2026305
Nov 5, 2026349
Nov 4, 2026365
Nov 3, 2026384
Nov 2, 2026379
Nov 1, 2026323
Oct 31, 2026285
Oct 30, 2026239
Oct 29, 2026152
Oct 28, 2026113
Oct 27, 202679
Oct 26, 2026140
Oct 25, 2026169
Oct 24, 2026223
Oct 23, 2026215
Oct 22, 2026343
Oct 21, 2026445
Oct 20, 2026465
Oct 19, 2026387
Oct 18, 2026374
Oct 17, 2026582
Oct 16, 2026981
Oct 15, 2026900
Oct 14, 2026802
Oct 13, 2026785
Oct 12, 2026773
Oct 11, 2026752
Oct 10, 2026475
Oct 9, 202682
Oct 8, 202651
Oct 7, 202649
Oct 6, 202653
Oct 5, 202651
Oct 4, 202668
Oct 3, 202672
Oct 2, 202680
Oct 1, 202677
Sep 30, 202687
Sep 29, 202685
Sep 28, 202684
Sep 27, 202656
Sep 26, 202697
Sep 25, 2026153
Sep 24, 2026175
Sep 23, 2026181
Sep 22, 2026173
Sep 21, 2026200
Sep 20, 2026206
Sep 19, 2026163
Sep 18, 202695
Sep 17, 202664
Sep 16, 202652
Sep 15, 202693
Sep 14, 202691
Sep 13, 202686
Sep 12, 202681
Sep 11, 202679
Sep 10, 202680
Sep 9, 202675
Sep 8, 202650
Sep 7, 202626

Each point is npm's rolling 7-day download count.

Health Score

59/100Good

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/1281664108-payload-revalidate.svg)](https://payloaddirectory.dev/plugins/1281664108-payload-revalidate)
HTML
<a href="https://payloaddirectory.dev/plugins/1281664108-payload-revalidate"><img src="https://payloaddirectory.dev/badge/1281664108-payload-revalidate.svg" alt="Payload Directory"></a>
Updated Aug 14, 2026Created Jun 26, 2026Published Aug 14, 2026

README

@pro-laico/payload-revalidate

Atomic Next.js cache revalidation for Payload CMS (App Router, Cache Components): id-keyed cache entries, field-driven busts that touch exactly what a change means, and a live dependency map showing what revalidates when.

Requires Payload ^3, React 19, and Next.js 16+ with Cache Components on the App Router. It's a Next cache tool — there is no non-Next mode. Set cacheComponents: true in next.config.

  • Field-driven write side — revalidatePlugin() hooks every collection/global; doc tags always, scoped list tags only when a scope's declared fields (or membership) change, draft saves only the draft lane, context.disableRevalidate honored.
  • Join-aware — a join field is a live query, not a stable reference, so create/delete/reassign of a member surgically busts only the affected parent's membership ({child}:join:{on}:{parentId}) — the parent whose "all my posts" list actually moved, never the others.
  • Atomic read side — inside your 'use cache' getters, one finder call fetches AND tags: findDoc / findDocByID (one doc = one entry, id-keyed, shared by every usage site), findIds (lists cache ids only — select: {} forced — with declared scopes like posts:list:featured), findGlobal. Atomic defaults baked in (depth: 0, errors → null), full local-API passthrough, returns typed from your generated payload-types, and user/req refused (a shared cache entry must not hold a requester-scoped read). Access is left to Payload's own default (overrideAccess: true) — pass overrideAccess: false to scope a read to what an anonymous visitor may see. References stay ids — "edit image 123 → only its own entry re-materializes, everywhere it's used." The low-level cacheDoc / cacheIds / cacheGlobal primitives stay exported for getters the finders can't express.
  • Visibility — a schema-derived reference graph + observed reads + a bust-event log at GET /api/revalidate-map, rendered by @pro-laico/payload-dev-tools at /dev/revalidate, or dumped as a Markdown doc with payload revalidate-map.
  • Seed integration — one precise flush at the end of a @pro-laico/payload-seed run.
// payload.config.ts — add it LAST so plugin-contributed collections get hooks too
plugins: [seedPlugin(), revalidatePlugin()]
// lib/cache.ts — seed the read helpers ONCE with your app's live Payload session
import config from '@payload-config'
import { createCacheHelpers } from '@pro-laico/payload-revalidate/cache'
import { getPayload } from 'payload'

export const { findDoc, findDocByID, findIds, findGlobal } = createCacheHelpers(getPayload({ config }))
// getters — 'use cache' + one finder call each
import { findDoc, findIds } from '@/lib/cache'

export async function getPost(slug: string) {
  'use cache'
  return findDoc('posts', { where: { slug: { equals: slug } }, as: slug })
}

export async function getRecentPostIds() {
  'use cache'
  return (await findIds('posts', { sort: '-publishedAt', limit: 12, list: 'recent' })).ids
}

The package never resolves Payload or your config itself — no globalThis stashes, no @payload-config alias tricks, no transpilePackages requirement. The handle you seed is the session that tags every read.

Map CLI

The plugin registers a payload revalidate-map command (Payload custom bin — no package path, no runner script). It prints the project's cache dependency map — tag vocabulary, per-collection blast radius, the full reference graph — as a Markdown doc straight from the config, no server booted. Handy for a REVALIDATION.md in the repo, or as context for an AI working in the project.

payload revalidate-map > REVALIDATION.md
payload revalidate-map --json --out revalidate-map.json   # raw inspection JSON

It reads config.custom.payloadRevalidate.options, so the output reflects the app's real prefix, opt-outs, and rules. Programmatic equivalent: renderRevalidateMap(buildStaticInspection(config)).

Documentation → · Example app: examples/revalidate-sandbox

MIT — not affiliated with Payload CMS.

Similar plugins