ExtantApe

payload plugin cache refresh

by ExtantApe
Other
v3
^3.80.0
MIT

Overview

Summary generated from the README

Adds an endpoint and a dashboard button to the Payload admin that calls revalidateTag for the tags you supply. Access is limited by a canRefresh function, with a confirmation step, CSRF-style origin checks, and a lock with cooldown. Defaults to stale-while-revalidate and can warm pages afterward. Requires Payload 3.80+ and Next.js 16+.

Features

  • Refresh Site Cache button on the dashboard, shown only to users allowed by canRefresh
  • Confirmation required, enforced by the endpoint for API calls too
  • Stale-while-revalidate by default, or expire tags immediately
  • Refresh only changed tags or everything
  • Optional page warming with per-fetch timeout and overall deadline
  • onRefresh audit hook reporting who, when, count and failed tags

Use cases

  • Let editors rebuild a Next.js site's cached pages after bulk content changes without redeploying
  • Restrict cache refreshes to admins and log each refresh to an audit trail
  • Pre-warm key pages after a refresh so visitors don't wait for rebuilds

From the author

Cache refresh for Payload: an admin button that refreshes the host's Next.js cache tags for the people the host allows, with a confirmation step, stale-while-revalidate by default, a targeted or full refresh, optional page warming and an audit hook.

Installation

npm i @extantape/payload-plugin-cache-refresh

0

Stars

0

Forks

0

Open Issues

6 days ago

Last Updated

385

Weekly Downloads

v0.2.0

npm Version

39.5 KB

Unpacked Size

0

Dependencies

GitHub stars

00 since Nov 15

Show data
GitHub stars by day (UTC)
DateStars
Dec 5, 20260
Dec 4, 20260
Dec 3, 20260
Dec 2, 20260
Dec 1, 20260
Nov 30, 20260
Nov 29, 20260
Nov 28, 20260
Nov 27, 20260
Nov 26, 20260
Nov 25, 20260
Nov 24, 20260
Nov 23, 20260
Nov 22, 20260
Nov 21, 20260
Nov 20, 20260
Nov 19, 20260
Nov 18, 20260
Nov 17, 20260
Nov 16, 20260
Nov 15, 20260
npm weekly downloads

354+166 since Nov 23

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 5, 2026354
Dec 4, 2026335
Dec 3, 2026315
Dec 2, 2026294
Dec 1, 202660
Nov 30, 2026244
Nov 29, 2026241
Nov 28, 2026239
Nov 27, 2026237
Nov 26, 2026221
Nov 25, 2026214
Nov 24, 2026188
Nov 23, 2026188

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

Health Score

78/100Excellent

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/1464319394-root.svg)](https://payloaddirectory.dev/plugins/1464319394-root)
HTML
<a href="https://payloaddirectory.dev/plugins/1464319394-root"><img src="https://payloaddirectory.dev/badge/1464319394-root.svg" alt="Payload Directory"></a>
Updated Nov 29, 2026Created Nov 19, 2026Published Nov 29, 2026

README

payload-plugin-cache-refresh

Cache refresh for Payload: a dashboard button that refreshes your Next.js site's cache tags, for the people you choose, after a confirmation.

Status: early. Version 0.2.0, a security release, is on npm; see the changelog. The plugin is covered by 110 unit tests with next/cache.js mocked: who may refresh, the same-site check and the allowed origins, the lock and cooldown, the confirmation step, a failing tag list, a tag that fails to refresh, a logger or hook that throws something other than an error, the audit hook, stale or expire, changed tags or everything, warming, and the words the button shows for each reply. It has not been run against a real Next.js app yet, the button has not been rendered in a browser, and the screen reader behavior is untested.

What it does

  • Adds a Refresh site cache button to the admin dashboard, shown only to users your canRefresh function allows.
  • Asks to confirm. The endpoint refuses to do anything until it is sent confirm: true, so the confirmation holds for API calls too.
  • Calls revalidateTag for each tag you give it. It knows nothing about your tag names, routes or roles.
  • Refreshes in stale-while-revalidate mode by default: pages keep showing while they rebuild. An option expires them at once instead.
  • If you give it changedTags, the button refreshes only those by default. The admin can choose Everything.
  • Can fetch a list of pages once after a refresh, one at a time, each with a timeout and all inside one deadline, so they are rebuilt before a visitor arrives. The reply says how many pages warmed, failed, timed out or were skipped. A failed fetch never fails the refresh.
  • Calls onRefresh with who, when and how many, for your audit trail.

Signed-out requests get 401. A signed-in user your rule refuses gets 403, and a rule that throws counts as a no. Payload's own auth applies to the endpoint.

Payload's CSRF check does not cover this endpoint: a form on another site can post text/plain with the admin's cookie and no preflight. So the plugin checks the request itself. The refresh needs Content-Type: application/json (415 otherwise), and the browser must show it came from this site: Sec-Fetch-Site must be same-origin if sent, and Origin must match the allowed origins if sent. A request with neither header gets 403. An Origin of null is always refused.

When the browser sends Origin, it is checked against the allowed origins. Those are allowedOrigins when you set it, and then only that list, never the request's own origin. It must hold at least one entry, and every entry must be an http or https address such as https://admin.example.org, or the plugin refuses to start with an error saying which entry to fix. Leave it unset to use Payload's serverURL, or the origin of the request URL when serverURL is empty (Payload's default) or isn't an http or https address. Set one of the two if a proxy changes the request URL.

A second press while a refresh runs, or within cooldownMs after one, gets 429.

If the tag list can't be read (a function throws, or a tag is empty or longer than 256 characters), nothing is refreshed.

If Next.js fails to refresh a tag, the plugin still tries the rest, so as much of the site as possible is fresh. The reply is then a 500 with refreshed: false, count (the tags that refreshed) and failed (the ones that didn't). Each failure is written to Payload's log. The reply never carries the error text. onRefresh gets only the tags that refreshed, with the failed count, so if you clear recorded tags there you clear only those. Nothing is warmed after a failure. The button says how many tags refreshed and how many didn't, and suggests trying again.

On its own, and with others

On its own: Cache Refresh needs only Payload and Next.js. It adds one endpoint and a dashboard button, and refreshes the tags your site records. It doesn't depend on any other plugin.

Needs: Payload ^3.80.0 and Next.js >=16.0.0 as peer dependencies, with React ^19.0.0 optional. No other EXTANT APE plugin is required.

Works with:

  • Audit Trail: your onRefresh can call Audit Trail's recordEvent, so each refresh is kept with who ran it and how many tags it refreshed. That's your own code, and neither plugin imports the other.

Color Theory: no direct link. The dashboard button uses its own --cache-refresh-* variables, which fall back to Payload's --theme-* colors, so it follows Color Theory's admin colors when its applyToAdmin option is on. Its focus ring falls back to a fixed orange.

Install

npm install @extantape/payload-plugin-cache-refresh

Needs Payload 3.80 or later and Next.js 16 or later, which has the two-argument revalidateTag.

import { cacheRefreshPlugin } from '@extantape/payload-plugin-cache-refresh'

export default buildConfig({
  plugins: [
    cacheRefreshPlugin({
      canRefresh: (req) => req.user?.role === 'admin',
      tags: ['pages', 'posts', 'menu'],
    }),
  ],
})

Regenerate Payload's import map after adding it, so the button is found.

Options

OptionWhat it does
canRefresh(req)Required. Returns true for users who may refresh.
tagsRequired. A list, or an async function returning one. What Everything refreshes.
changedTags({ req })Tags changed since the last refresh, for example ones your scripts recorded. When given, the button offers Only what changed (the default) and Everything.
mode'stale' (default) or 'expire'. Stale calls revalidateTag(tag, profile). Expire calls revalidateTag(tag, { expire: 0 }), so the next visit waits for a fresh page.
profileThe profile for stale mode. Default 'max'.
warmPathsA list of paths, or a function returning one, fetched after a refresh. A path starts with a single / and has no backslash. Anything else, such as //host or /\host, is refused and counted as failed. The URL is built on warmBaseUrl and its origin is checked again before the fetch. Redirects are not followed.
warmBaseUrlThe site's address, such as https://example.org. Warming is off without it.
warmTimeoutMsTime for each warming fetch. Default 5000.
warmDeadlineMsTotal time for all warming. Pages left when it passes are skipped and reported. Default 15000.
cooldownMsTime after a refresh before the next is accepted. Default 5000.
allowedOriginsOrigins a refresh may come from, checked when the browser sends Origin. When set, only this list is used, and it needs at least one entry, each an http or https address, or the plugin refuses to start. Default Payload's serverURL, else the request's origin.
onRefresh(report)Gets who (id, collection, email), at, count, failed, scope, mode and tags. tags holds only the tags that refreshed, and failed counts the ones that didn't. If it throws, the refresh stays and the response says audited: false. It isn't called when zero tags were refreshed.
endpointPathDefault /cache-refresh.
adminButtonDefault true. Set false and import CacheRefreshButton from @extantape/payload-plugin-cache-refresh/client to place it yourself.

The plugin never clears your recorded changed tags. Do that in onRefresh, which receives the tags it refreshed.

The button's words can be replaced with the text prop (its partial, noneRefreshed and partialNotAudited entries cover a refresh that only partly went through), and its colors with --cache-refresh-ink, --cache-refresh-paper, --cache-refresh-line and --cache-refresh-focus.

Limits

  • A refresh is a request to Next.js, and in stale mode the rebuild happens when a page is next visited. Warming is how you bring that forward.
  • Expiry is not undone if a later step fails. The tag list is checked first for that reason.
  • The lock and cooldown live in one server process. Several instances each keep their own.
  • It refreshes the cache of the Next.js process serving the request. Other servers or a CDN in front need their own handling.

License

MIT. Copyright (c) 2026 EXTANT APE.

Similar plugins