-
Notifications
You must be signed in to change notification settings - Fork 3.2k
feat(payload, next): DatabaseCache implementation /w next/cache + in-memory #7712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
I like the ideas here. I have some concerns with the implementation as I see it described, though I haven't reviewed the code yet. I feel like the API for this is not at all complete and should be designed better. |
A) Agree With InMemory it should already work - you can access its Map storage for payload/packages/payload/src/cache/in-memory-database-cache/InMemoryDatabaseCacheStorage.ts Line 6 in 0f7ed06
So that's the main block here. But people definetely want to use Next.js caching in a first place for frontend revalidation. In fact, that's my main motivation for the PR, because I see a lot of people are struggling with caching / invalidation. Overall, do you think it's right from me to cache |
|
This PR is stale due to lack of activity. To keep the PR open, please indicate that it is still relevant in a comment below. |
Description
Adds an implementation of caching to Payload.
Usage
Simply providing
cache: trueinto args will cache the current operation:With the REST API - query parameter
?cache=true.Configuration / cache adapters
By default, if


cacheis not provided -inMemoryDatabaseCachewill be used.Any implemented database cache adapter accepts
loggingandttloptions.Example of
logging: true- useful for debuggingttl- Time To Live for the cached values, by default it's 1 hour. Providingfalsewill disable TTL.inMemoryDatabaseCacheprobably won't work well on a server-less envs like Vercel!Fields Cache Indexes
By default, only
idfield is used for revalidation of thefindOnecalls, you can providecacheIndex: trueto a needed field (for example a common one - slug).The implementation as well handles the cache invalidation for us, no need to write revalidation hooks more!
That means if you're using
nextDatabaseCache- ISR should happen automatically as well. This also includesdepthparameter handling.Underlying API calls
payload.dbdirectly and stores its result into the implemented storage.You can use it like this:
ttlcan as well be resolved dynamically viaTTLResolveFunction.No tests / docs and probably some things don't work normally yet
Type of change
Checklist: