#Implementing caching

1 messages · Page 1 of 1 (latest)

olive blaze
#

Hi Payload-server! I'm looking to implement caching of my frontend, as it is a mainly static marketing landing page site. Payload is used as a website-builder in this instance, allowing other people in the department to build out the website without the need to rebuild and redeploy every time.

We are self-hosting in Openshift/Kubernetes, and serve the application across 2 pods. I need to have a shared cache solution, so invalidating a tagged cache does it for both running instances at the same time. I've tried setting up Redis for this, with no luck so far.

I managed to cache my LocalAPI responses/fetches, but that made Live Preview stop working, so a caching solution would need to take live preview into account somehow and only serve cached content to actual website visitors, not editors working in the admin panel.

If anyone has set up a solution akin to what I need, I would love to get some ideas or pinpointers to get the ball rolling, or look at some examples.

errant surgeBOT
pallid thorn
#

Hi @olive blaze , what exactly didn't work in setting up Redis to handle the shared cache ? I have exactly the same setup as you and it works just fine !

olive blaze
#

I've just been trying to configure a custom cache-handler with various GPTs (life of a solo dev 🥲 ) and none of they have compiled/functioned correctly. Do you have a example of how you configured yours?

pallid thorn
olive blaze
#

that link gives me a 404, but it looks like the neshca/cache-handler package, which unfortunately doesn't work with NextJS 15 yet, which my project is running (running Payload v3 atm)

pallid thorn
olive blaze
#

nice! will take a look.

Did you manage to cache your LocalAPI-calls and still maintain livepreview functionality? when I wrapped my fetch-functions for payload collections in "unstable_cache()" it broke my livepreview, requiring either a publish of the document or a reload of the page to view the changes that had been made

pallid thorn
#

I am not using livepreview atm, I will re-introduce it sometime soon but I didn't have the time to spend on that. I was using it before implementing cache methods like unstable_cache. I guess you could wrap the cache logic into an util and disable the cache when you are in draftMode

olive blaze
#

if you have an example of your implemented cache handler i'd love to take a look at it if possible :)

pallid thorn
#

Not at all, what exactly do you want to see ? Bear in mind that I'm using Next 14 for now but happy to help

olive blaze
#

ah okay, then it might not be too helpful. specifically looking for a nextjs 15 compatible implementation, never used Redis or any caching system before so it's all just a bit overwhelming (and for GPT-agents too atm haha).

I have got unstable_cache to work nicely with live preview now tho, so for now we will just live with content being stale for visitors for a while until the revalidate kicks in :) will probably have another go once neshca gets a 2.0 release, or we really need to be able to invalidate tags across multiple pods

errant surgeBOT
pallid thorn
#

Yeah, everything is a bit more obscure when you try to avoid using Vercel where all the magic happens 😄

olive blaze
daring gate
#

I have a similar setup but deploying in azure.
I am think of implementing a endpoint that handles revalidation in the nextjs website that I will call from the payload instance in a aftersave hook.