Payload Adsign Plugin

Revalidation

Opt collections and globals into plugin-managed revalidation via `custom.revalidate`

In autoMode (the default), anything with custom.revalidate set gets a revalidation hook attached at plugin init. true enables the defaults; object form lets you override.

Setup

src/collections/Articles/index.ts
import type { CollectionConfig } from 'payload';

export const Articles: CollectionConfig = {
    slug: 'articles',
    custom: {
        revalidate: {
            cacheTagFields: ['slug'],
        },
    },
    fields: [
        { name: 'slug', type: 'text' },
        { name: 'myProjects', type: 'relationship', relationTo: 'projects', hasMany: true },
    ],
};
src/payload.config.ts
adsignPlugin({
    revalidation: {
        url: process.env.REVALIDATE_CACHE_URL,
        secret: process.env.REVALIDATE_CACHE_SECRET_TOKEN,
        source: 'adsign-cms',
    },
});

Short form — just opt in with defaults:

custom: { revalidate: true }

What gets invalidated

When a doc changes, the plugin fires tags for:

  • The collection itself and each cacheTagFields value on the doc.
  • Every doc reachable through a relationship/upload field on the changed doc.
  • Every doc in other collections that references this one via a relationship/upload field.

All of that is automatic — no extra config.

Globals

Same opt-in as collections. Globals are singletons so the short form is enough:

src/globals/Header.ts
export const Header: GlobalConfig = {
    slug: 'header',
    custom: { revalidate: true },
    fields: [/* ... */],
};

A change fires the header tag (plus ${source}_header when source is set).

Wire format

One POST per tag. Body is always { secret, tag }:

POST <revalidation.url>
Content-Type: application/json

{ "secret": "…", "tag": "articles_hello-world" }

When source is configured, it's prefixed into every tag at the publisher:

{ "secret": "…", "tag": "adsign-cms_articles_hello-world" }

Opting out — legacyMode

To keep the old body shape and wire revalidateHook manually, set mode: 'legacyMode':

adsignPlugin({
    revalidation: {
        url: process.env.REVALIDATE_CACHE_URL,
        secret: process.env.REVALIDATE_CACHE_SECRET_TOKEN,
        mode: 'legacyMode',
    },
});

In legacyMode, source is forbidden and any collection/global with custom.revalidate set will cause the plugin to throw at init.

Next.js receiver

app/api/revalidate/route.ts
import type { NextRequest } from 'next/server';
import { revalidateFromPayload } from '@adsign/payload-adsign-plugin/next';

export async function POST(request: NextRequest): Promise<Response> {
    return revalidateFromPayload(request, {
        secret: process.env.REVALIDATE_CACHE_SECRET_TOKEN!,
    });
}

revalidateFromPayload parses the body, validates body.secret, and calls revalidateTag(body.tag, 'max'). Pass { secret, profile } to override the revalidate profile.

On this page