Registry / storage / payload-plugin-cache

payload-plugin-cache

JSON →
library0.9.8jsnpmunverified

Payload CMS v3 plugin for cache invalidation using stable cache tags. Version 0.9.8, pre-1.0.0 with regular releases. Connects Payload write events (afterOperation/afterChange hooks) to external cache systems via adapters. Ships TypeScript types, ESM-only, requires Next.js 15/16 and Payload ^3.80.0 as peer dependencies. Provides cache tag generation, revalidation strategies, and a registry for frontend-side tag resolution. Supports collection/global cache strategies, path-based invalidation, custom tags, and predicates.

npm install payload-plugin-cache
INSTALL
IMPORT
SIG · PAYLOAD-PLUGIN-CAC
P
payload-plugin-cache
storagejavascriptv0.9.8
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

cacheTags
import { cacheTags } from 'payload-plugin-cache'
const cacheTags = require('payload-plugin-cache')
ESM-only package; CommonJS require will fail
defineCachePlugin
import { defineCachePlugin } from 'payload-plugin-cache'
import { defineCachePlugin } from 'payload-plugin-cache/defineCachePlugin'
Not a default export; named import from root
nextCacheAdapter
import { nextCacheAdapter } from 'payload-plugin-cache/next'
import { nextCacheAdapter } from 'payload-plugin-cache'
Adapter is exported from a subpath export 'payload-plugin-cache/next'
findAllReferences
import { findAllReferences } from 'payload-plugin-cache'
import findAllReferences from 'payload-plugin-cache'
Not a default export; named import

Full Payload CMS configuration using defineCachePlugin for pages collection and globals with Next.js cache adapter.

import { buildConfig } from 'payload' import { cacheTags, defineCachePlugin, findAllReferences } from 'payload-plugin-cache' import { nextCacheAdapter } from 'payload-plugin-cache/next' const { plugin: cachePlugin, registry: cacheRegistry } = defineCachePlugin({ adapter: nextCacheAdapter(), collections: { pages: { path: ({ doc }) => (typeof doc.populatedUrl === 'string' ? doc.populatedUrl : undefined), predicates: { isSearchPage: ({ doc }) => doc.slug === 'search', }, renderTags: async ({ doc, locale, path, searchParams, predicates }) => [ path ? cacheTags.route({ path, locale }) : null, cacheTags.document({ collection: 'pages', id: doc.id, locale }), ...findAllReferences(doc).map((reference) => cacheTags.document({ collection: reference.collection, id: reference.id, locale, }), ), cacheTags.custom('sitemap'), predicates.isSearchPage ? cacheTags.custom('searches') : null, predicates.isSearchPage && searchParams?.get('q') ? cacheTags.custom(`search:${searchParams.get('q')}`) : null, ], }, team: { revalidateOn: ['update', 'delete'], renderTags: () => [cacheTags.custom('page')], }, }, globals: { settings: { renderTags: () => [cacheTags.global('settings'), cacheTags.custom('sitemap')], }, header: { renderTags: () => [cacheTags.global('header')], revalidatePaths: () => [{ path: '/', type: 'layout' }], }, footer: { renderTags: () => [cacheTags.global('footer')], revalidatePaths: () => [{ path: '/', type: 'layout' }], }, }, }) export { cacheRegistry } export default buildConfig({ plugins: [cachePlugin], collections: [ { slug: 'pages', fields: [] }, { slug: 'team', fields: [] }, ], globals: [ { slug: 'settings', fields: [] }, { slug: 'header', fields: [] }, { slug: 'footer', fields: [] }, ], })
Debug
Known issues
gotchaESM-only package — require() will throw at runtime
fix
Use ES module imports (import/export) or configure Node.js to handle ESM
affects: >=0.0.0
breakingPre-1.0.0 API may change without major version bump
fix
Pin to exact version and monitor changelog
affects: <1.0.0
gotchanextCacheAdapter requires Next.js 15/16 and Payload ^3.80.0 peer deps
fix
Ensure matching peer dependencies or use a different adapter
affects: >=0.0.0
deprecatedcachePlugin standalone export may be deprecated in favor of defineCachePlugin
fix
Use defineCachePlugin which returns both plugin and registry
affects: >=0.9.0
gotchaRegistry must be exported or shared between Payload and frontend for tag resolution to work
fix
Export cacheRegistry from config and import it in frontend code
affects: >=0.9.0
Errors
Common errors & fixes
Cannot find module 'payload-plugin-cache/next'
Subpath export not configured or wrong import path
fix
Use import { nextCacheAdapter } from 'payload-plugin-cache/next' (check package.json exports field)
defineCachePlugin is not a function
Using CommonJS require instead of ESM import
fix
Switch to import { defineCachePlugin } from 'payload-plugin-cache'
TypeError: adapter is not a function or object
Missing or incorrectly imported adapter
fix
Ensure adapter is imported correctly: import { nextCacheAdapter } from 'payload-plugin-cache/next'
Error: No adapter provided to defineCachePlugin
Missing adapter option in plugin configuration
fix
Add adapter: nextCacheAdapter() (or custom adapter) to defineCachePlugin options
Upgrade
Version history
0.9.8latest on npm
Audit
Dependencies
nextoptionalPeer dependency for Next.js cache adapter (nextCacheAdapter) and revalidation
payloadrequiredPeer dependency — core Payload CMS framework required
Agent activity
6 hits · last 30 days
node
6
Resources
payload-plugin-cache — npm install payload-plugin-cache · libregistry