I'm looking for best practises for caching inside containers. I have a .NET 6 backend which uses MemoryCache to store certain keys and values to improve the overall performance and lessen the load on the 3rd party backend.
Turns out that MemoryCache is pod specific (duh), which sadly took me way too long to figure out why I had 5 different cache responses (I had 5 active pods). How have people been resolving such an issue? Do you divert to a volume / database?
✅ 1
q
quick-dentist-45681
08/22/2022, 8:19 AM
One common approach is to use a shared redis or memcached (or any other similar type of service). You probably want to aim for network+memory instead of network+disk for that kind of thing (depending on your needs ofc).
k
kind-nightfall-56861
08/22/2022, 8:22 AM
I would prefer a memory approach, ya.. It's a non-issue if the caching suddenly gets whiped, but they need to be equal over all running pods.
q
quick-dentist-45681
08/22/2022, 8:25 AM
In that case, I would look at deploying a redis instance in the cluster and use that. You could optionally go for a HA setup using Sentinel, but that's often more complexity than it's worth for a simple cache.
✅ 1
k
kind-nightfall-56861
08/22/2022, 8:27 AM
Aight, I wasn't yet aware of https://redis.io/, so thanks for the feedback 😄