Wraps Payload's Local API in a cached layer built on Next.js unstable_cache. Cached operations are revalidated automatically with revalidateTag when documents are created, changed or deleted. You configure it through a plugin in payload.config.ts and call a cached Payload wrapper in your pages. It is experimental and targets Payload 3.0 beta.
Installation
npm i @payload-enchants/cached-local-api335
Stars
28
Forks
28
Open Issues
1 years ago
Last Updated
107
Weekly Downloads
v1.2.2
npm Version
138.0 KB
Unpacked Size
0
Dependencies
335+2 since Sep 7
| Date | Stars |
|---|---|
| Dec 6, 2026 | 335 |
| Dec 5, 2026 | 335 |
| Dec 4, 2026 | 335 |
| Dec 3, 2026 | 335 |
| Dec 2, 2026 | 335 |
| Dec 1, 2026 | 335 |
| Nov 30, 2026 | 335 |
| Nov 29, 2026 | 335 |
| Nov 28, 2026 | 335 |
| Nov 27, 2026 | 335 |
| Nov 26, 2026 | 335 |
| Nov 25, 2026 | 335 |
| Nov 24, 2026 | 335 |
| Nov 23, 2026 | 335 |
| Nov 22, 2026 | 335 |
| Nov 21, 2026 | 335 |
| Nov 20, 2026 | 335 |
| Nov 19, 2026 | 336 |
| Nov 18, 2026 | 336 |
| Nov 17, 2026 | 335 |
| Nov 16, 2026 | 335 |
| Nov 15, 2026 | 335 |
| Nov 14, 2026 | 335 |
| Nov 13, 2026 | 335 |
| Nov 12, 2026 | 335 |
| Nov 11, 2026 | 335 |
| Nov 10, 2026 | 335 |
| Nov 9, 2026 | 335 |
| Nov 8, 2026 | 335 |
| Nov 7, 2026 | 335 |
| Nov 6, 2026 | 335 |
| Nov 5, 2026 | 335 |
| Nov 4, 2026 | 335 |
| Nov 3, 2026 | 335 |
| Nov 2, 2026 | 335 |
| Nov 1, 2026 | 335 |
| Oct 31, 2026 | 335 |
| Oct 30, 2026 | 335 |
| Oct 29, 2026 | 335 |
| Oct 28, 2026 | 335 |
| Oct 27, 2026 | 335 |
| Oct 26, 2026 | 335 |
| Oct 25, 2026 | 335 |
| Oct 24, 2026 | 334 |
| Oct 23, 2026 | 334 |
| Oct 22, 2026 | 334 |
| Oct 21, 2026 | 334 |
| Oct 20, 2026 | 334 |
| Oct 19, 2026 | 334 |
| Oct 18, 2026 | 334 |
| Oct 17, 2026 | 334 |
| Oct 16, 2026 | 334 |
| Oct 15, 2026 | 334 |
| Oct 14, 2026 | 334 |
| Oct 13, 2026 | 334 |
| Oct 12, 2026 | 334 |
| Oct 11, 2026 | 333 |
| Oct 10, 2026 | 333 |
| Oct 9, 2026 | 333 |
| Oct 8, 2026 | 333 |
| Oct 7, 2026 | 333 |
| Oct 6, 2026 | 333 |
| Oct 5, 2026 | 333 |
| Oct 4, 2026 | 333 |
| Oct 3, 2026 | 333 |
| Oct 2, 2026 | 333 |
| Oct 1, 2026 | 333 |
| Sep 30, 2026 | 333 |
| Sep 29, 2026 | 333 |
| Sep 28, 2026 | 333 |
| Sep 27, 2026 | 333 |
| Sep 26, 2026 | 333 |
| Sep 25, 2026 | 333 |
| Sep 24, 2026 | 333 |
| Sep 23, 2026 | 333 |
| Sep 22, 2026 | 333 |
| Sep 21, 2026 | 333 |
| Sep 20, 2026 | 333 |
| Sep 19, 2026 | 333 |
| Sep 18, 2026 | 333 |
| Sep 17, 2026 | 333 |
| Sep 16, 2026 | 333 |
| Sep 15, 2026 | 333 |
| Sep 14, 2026 | 333 |
| Sep 13, 2026 | 333 |
| Sep 12, 2026 | 333 |
| Sep 11, 2026 | 333 |
| Sep 10, 2026 | 333 |
| Sep 9, 2026 | 333 |
| Sep 8, 2026 | 333 |
| Sep 7, 2026 | 333 |
Shared by 7 plugins in r1tsuu/payload-enchants.
107−2.1K since Sep 7
| Date | Weekly downloads |
|---|---|
| Dec 6, 2026 | 107 |
| Dec 5, 2026 | 107 |
| Dec 4, 2026 | 50 |
| Dec 3, 2026 | 51 |
| Dec 2, 2026 | 22 |
| Dec 1, 2026 | 23 |
| Nov 30, 2026 | 23 |
| Nov 29, 2026 | 51 |
| Nov 28, 2026 | 51 |
| Nov 27, 2026 | 46 |
| Nov 26, 2026 | 43 |
| Nov 25, 2026 | 44 |
| Nov 24, 2026 | 44 |
| Nov 23, 2026 | 43 |
| Nov 22, 2026 | 27 |
| Nov 21, 2026 | 35 |
| Nov 20, 2026 | 36 |
| Nov 19, 2026 | 39 |
| Nov 18, 2026 | 36 |
| Nov 17, 2026 | 35 |
| Nov 16, 2026 | 37 |
| Nov 15, 2026 | 31 |
| Nov 14, 2026 | 20 |
| Nov 13, 2026 | 18 |
| Nov 12, 2026 | 13 |
| Nov 11, 2026 | 16 |
| Nov 10, 2026 | 46 |
| Nov 9, 2026 | 46 |
| Nov 8, 2026 | 50 |
| Nov 7, 2026 | 56 |
| Nov 6, 2026 | 56 |
| Nov 5, 2026 | 60 |
| Nov 4, 2026 | 85 |
| Nov 3, 2026 | 55 |
| Nov 2, 2026 | 55 |
| Nov 1, 2026 | 46 |
| Oct 31, 2026 | 51 |
| Oct 30, 2026 | 62 |
| Oct 29, 2026 | 58 |
| Oct 28, 2026 | 29 |
| Oct 27, 2026 | 31 |
| Oct 26, 2026 | 49 |
| Oct 25, 2026 | 49 |
| Oct 24, 2026 | 61 |
| Oct 23, 2026 | 50 |
| Oct 22, 2026 | 69 |
| Oct 21, 2026 | 91 |
| Oct 20, 2026 | 90 |
| Oct 19, 2026 | 94 |
| Oct 18, 2026 | 108 |
| Oct 17, 2026 | 101 |
| Oct 16, 2026 | 114 |
| Oct 15, 2026 | 116 |
| Oct 14, 2026 | 144 |
| Oct 13, 2026 | 149 |
| Oct 12, 2026 | 130 |
| Oct 11, 2026 | 118 |
| Oct 10, 2026 | 102 |
| Oct 9, 2026 | 91 |
| Oct 8, 2026 | 70 |
| Oct 7, 2026 | 20 |
| Oct 6, 2026 | 16 |
| Oct 5, 2026 | 11 |
| Oct 4, 2026 | 8 |
| Oct 3, 2026 | 19 |
| Oct 2, 2026 | 24 |
| Oct 1, 2026 | 45 |
| Sep 30, 2026 | 51 |
| Sep 29, 2026 | 52 |
| Sep 28, 2026 | 54 |
| Sep 27, 2026 | 181 |
| Sep 26, 2026 | 941 |
| Sep 25, 2026 | 1,760 |
| Sep 24, 2026 | 2,750 |
| Sep 23, 2026 | 3,057 |
| Sep 22, 2026 | 3,206 |
| Sep 21, 2026 | 3,288 |
| Sep 20, 2026 | 8,867 |
| Sep 19, 2026 | 10,825 |
| Sep 18, 2026 | 10,443 |
| Sep 17, 2026 | 9,980 |
| Sep 16, 2026 | 9,945 |
| Sep 15, 2026 | 11,116 |
| Sep 14, 2026 | 11,564 |
| Sep 13, 2026 | 6,014 |
| Sep 12, 2026 | 3,495 |
| Sep 11, 2026 | 3,552 |
| Sep 10, 2026 | 3,159 |
| Sep 9, 2026 | 3,035 |
| Sep 8, 2026 | 1,976 |
| Sep 7, 2026 | 2,189 |
Each point is npm's rolling 7-day download count.
Health Score
Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.
Badge for your README
[](https://payloaddirectory.dev/plugins/684372049-cached-local-api)<a href="https://payloaddirectory.dev/plugins/684372049-cached-local-api"><img src="https://payloaddirectory.dev/badge/684372049-cached-local-api.svg" alt="Payload Directory"></a>README
unstable_cache (experimental)This package allows to cache the following operations:
findfindByIDfindOne - new operation, find one by specific field, for example slugfindGlobalcountrevalidateTag on Create / Change / Delete.pnpm add @payload-enchants/cached-local-api
Add to the separated file (see below for the config type)
import { buildCachedPayload } from '@payload-enchants/cached-local-api';
import { revalidateTag, unstable_cache } from 'next/cache';
export const { cachedPayloadPlugin, getCachedPayload } = buildCachedPayload({
// collections list to cache
collections: [
{
findOneFields: ['slug'],
slug: 'posts',
},
],
// Log when revalidation runs or operation cache HIT / SKIP
loggerDebug: true,
globals: [{ slug: 'header' }],
revalidateTag,
options: {},
unstable_cache,
});
Add into your payload.config.ts:
import { cachedPayloadPlugin } from './cached-local-api';
export default buildConfig({
// ...your config
plugins: [cachedPayloadPlugin],
});
import configPromise from '@payload-config';
import { getPayloadHMR } from '@payloadcms/next/utilities';
import { getCachedPayload } from '../../../cached-local-api';
const Page = async () => {
const payload = await getPayloadHMR({
config: configPromise,
});
const cachedPayload = getCachedPayload(payload);
const posts = await cachedPayload.find({ collection: 'posts' });
const postBySlug = await cachedPayload.findOne({ collection: 'posts', value: 'home', depth: 2 });
// In this case it's not required as `slug` field is the first item in `findOneFields` array.
const postBySlugExplict = await cachedPayload.findOne({
collection: 'posts',
field: 'slug',
value: 'home',
});
// by id
if (postBySlug) {
const postByID = await cachedPayload.findByID({
collection: 'posts',
id: postBySlug?.id ?? '',
});
}
// count
const { totalDocs } = await cachedPayload.count({ collection: 'posts' });
return (
<div>
{posts.docs.map((each) => (
<div key={each.id}>{each.title}</div>
))}
</div>
);
};
export default Page;
export type Args = {
/** List of collections slugs that should use cache */
collections?: Array<{
/** array with the fields to use in findOne (name or config, see below) */
findOneFields?: (FindOneFieldConfig | string)[];
slug: keyof GeneratedTypes['collections'];
}>;
/** List of globals slugs that should use cache */
globals?: Array<{
slug: keyof GeneratedTypes['globals'];
}>;
/** Additional options */
options?: Options;
/** Next.js revalidateTag */
revalidateTag: (tag: string) => void;
/** Next.js unstable_cache */
unstable_cache: UnstableCache;
/**
* (experiment): Instead of revalidating each collection document separately
* 'simpleCache' revalidates all cached data on Payload database update
* */
useSimpleCacheStrategy?: boolean;
};
export type FindOneFieldConfig = {
buildWhere?: (args: {
args: FindOneArgs<any>;
fieldName: string;
shouldCache: boolean;
value: unknown;
}) => Where;
getFieldFromDoc?: (doc: Record<string, any>) => unknown;
name: string;
};
export type Options = {
// custom tag build
buildTagFind?: (args: { slug: string }) => string;
buildTagFindByID?: (args: { id: number | string; slug: string }) => string;
buildTagFindGlobal?: (args: { slug: string }) => string;
// If not provided - returns `true`
shouldCacheCountOperation?: (args: CountArgs) => Promise<boolean> | boolean;
shouldCacheFindByIDOperation?: (args: FindByIDArgs) => Promise<boolean> | boolean;
shouldCacheFindGlobalOperation?: (args: FindGlobalArgs) => Promise<boolean> | boolean;
shouldCacheFindOperation?: (args: FindArgs) => Promise<boolean> | boolean;
// If not provided - returns `true`
shouldRevalidateGlobalOnChange?: (
args: Parameters<GlobalAfterChangeHook>[0],
) => Promise<boolean> | boolean;
shouldRevalidateOnChange?: (
args: Parameters<CollectionAfterChangeHook>[0],
) => Promise<boolean> | boolean;
shouldRevalidateOnDelete?: (
args: Parameters<CollectionAfterDeleteHook>[0],
) => Promise<boolean> | boolean;
// Completely disable caching in any operation
disableCache?: boolean;
};
payload cache
Automatic Next.js 16 and Vercel cache tagging and invalidation for Payload reads
74321/wk0v3 v4
payload revalidate
Field-driven Next.js cache revalidation for Payload with id-keyed cached finders and a dependency map
59240/wk18v3
payloadcms redis cache
Redis client helper for caching Payload collection data in Next.js apps
3813/wk2v?
payload upstash
Upstash Redis key-value adapter for Payload's built-in KV store
82333/wk7v3 v4
payload kv
Store counters, feeds and expiring data in Redis or KV stores while querying them as normal Payload fields
771.4k/wk0v3 v4
payload redis cache
Redis-backed cache layer for Payload API endpoints, keyed by user collection and request URL
48271/wk64v1