
Company News
Meet the Socket Team at RSAC and BSidesSF 2026
Join Socket for live demos, rooftop happy hours, and one-on-one meetings during BSidesSF and RSA 2026 in San Francisco.
payload-cached
Advanced tools
payload-cached manages cache invalidation for your Payload CMS collections.
Features
# pnpm
pnpm add payload-cached
# yarn
yarn add payload-cached
# npm
npm install payload-cached
Add the plugin to your payload.config.ts:
import { buildConfig } from "payload";
import { cachedPlugin } from "payload-cached";
export default buildConfig({
collections: [Posts, Categories, Users],
plugins: [
cachedPlugin({
collections: {
posts: ["create", "update", "delete"],
categories: ["create", "update"],
// users: false, // Disable tracking for users
},
publishHandler: async (changes) => {
// Optional: Custom handler for published changes
console.log("Published changes:", changes);
},
}),
],
});
The plugin automatically adds a Publish button to your admin panel header. Click it to process all queued changes and invalidate cache tags.
You can also trigger publishing programmatically:
Node.js:
import config from "@payload-config";
import { getPayload } from "payload";
const payload = await getPayload({ config });
const response = await fetch(`${process.env.PAYLOAD_API_URL}/cache-plugin/publish`, {
method: "POST",
});
Edge runtime:
const response = await fetch(`${process.env.PAYLOAD_API_URL}/cache-plugin/publish`, {
method: "POST",
});
The cachedPlugin accepts the following configuration:
| Option | Default | Description |
|---|---|---|
collections | All collections tracked | Per-collection configuration for which operations to track |
publishHandler | - | Optional callback function called after changes are published |
You can configure tracking per collection:
cachedPlugin({
collections: {
// Track all operations (create, update, delete)
posts: ["create", "update", "delete"],
// Track only updates
categories: ["update"],
// Disable tracking completely
users: false,
// Use default operations (create, update, delete)
// If not specified, defaults to all operations
},
})
Change Tracking: When documents are created, updated, or deleted, the plugin automatically adds them to a publish queue.
Dependency Resolution: When publishing, the plugin analyzes relationships between collections and invalidates cache tags for dependent documents.
Cache Invalidation: Uses Next.js revalidateTag to invalidate cache tags for affected collections.
Publish Queue: Changes are queued until you explicitly publish them, allowing you to batch invalidations.
Here's a complete example showing how to integrate payload-cached:
// payload.config.ts
import { buildConfig } from "payload";
import { cachedPlugin } from "payload-cached";
import { Posts } from "./collections/Posts";
import { Categories } from "./collections/Categories";
export default buildConfig({
collections: [Posts, Categories],
plugins: [
cachedPlugin({
collections: {
posts: ["create", "update", "delete"],
categories: ["update"], // Only track updates for categories
},
publishHandler: async (changes) => {
// Optional: Send webhook, update external cache, etc.
await fetch("https://api.example.com/webhook", {
method: "POST",
body: JSON.stringify(changes),
});
},
}),
],
});
// app/api/revalidate/route.ts
import { NextRequest, NextResponse } from "next/server";
import config from "@payload-config";
import { getPayload } from "payload";
export async function POST(request: NextRequest) {
const payload = await getPayload({ config });
const response = await fetch(
`${process.env.PAYLOAD_API_URL}/cache-plugin/publish`,
{
method: "POST",
}
);
if (!response.ok) {
return NextResponse.json(
{ error: "Failed to publish changes" },
{ status: 500 }
);
}
return NextResponse.json({ success: true });
}
The plugin provides two endpoints:
/cache-plugin/publishPublishes all queued changes and invalidates cache tags.
Response:
200 OK - Changes published successfully200 OK with message "No changes to publish" - Queue is empty/cache-plugin/checkChecks the status of the publish queue.
# Install dependencies
pnpm install
# Start development server
pnpm dev
# Build the plugin
pnpm build
# Run tests
pnpm test
MIT
FAQs
Payload Plugin for Cached Data
We found that payload-cached demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Join Socket for live demos, rooftop happy hours, and one-on-one meetings during BSidesSF and RSA 2026 in San Francisco.

Research
/Security News
Malicious Packagist packages disguised as Laravel utilities install an encrypted PHP RAT via Composer dependencies, enabling remote access and C2 callbacks.

Research
/Security News
OpenVSX releases of Aqua Trivy 1.8.12 and 1.8.13 contained injected natural-language prompts that abuse local AI coding agents for system inspection and potential data exfiltration.