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: [] },
],
})
Errors
Common errors & fixes
Cannot find module 'payload-plugin-cache/next'
Subpath export not configured or wrong import path
fixUse import { nextCacheAdapter } from 'payload-plugin-cache/next' (check package.json exports field) defineCachePlugin is not a function
Using CommonJS require instead of ESM import
fixSwitch to import { defineCachePlugin } from 'payload-plugin-cache' TypeError: adapter is not a function or object
Missing or incorrectly imported adapter
fixEnsure adapter is imported correctly: import { nextCacheAdapter } from 'payload-plugin-cache/next' Error: No adapter provided to defineCachePlugin
Missing adapter option in plugin configuration
fixAdd adapter: nextCacheAdapter() (or custom adapter) to defineCachePlugin options
Audit
Dependencies
nextoptionalPeer dependency for Next.js cache adapter (nextCacheAdapter) and revalidation
payloadrequiredPeer dependency — core Payload CMS framework required