![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@payload-enchants/cached-local-api
Advanced tools
unstable_cache
(experimental)This package allows to cache the following operations:
find
findByID
findOne
- new operation, find one by specific field, for example slugfindGlobal
count
revalidateTag
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;
};
FAQs
## Description:
The npm package @payload-enchants/cached-local-api receives a total of 162 weekly downloads. As such, @payload-enchants/cached-local-api popularity was classified as not popular.
We found that @payload-enchants/cached-local-api demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.