Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to evict cache in multiple pods? I have two Openshift pods and I want to send a HTTP request for evict cache in both pods

I have two microservices pods in Openshift, I want to clean cache both microservices. I have a endpoint that clear-evict cache, the request only enter in one pod. How to avoid restart the pods for clear-cache? I use 2.1.10 springboot and I have a cron configurated every two hours but I want to clean cache in HTTP Request.

I use @Cacheable from org.springframework.cache.annotation in the request and org.springframework.cache.CacheManager.clear for evict/clean the cache.

like image 677
davidleongz Avatar asked Dec 02 '25 08:12

davidleongz


1 Answers

Just like other services in the Spring Framework, the caching service is an abstraction, not an implementation and requires the use of an implementation to store the cache data. This abstraction is materialized by the org.springframework.cache.Cache and org.springframework.cache.CacheManager interfaces.

You have not spoken about which is your Spring cache implementation, so I suppose that you are using the default implementation.

By default, Spring chooses java.util.concurrent.ConcurrentMap. This implementation stores your data in-memory and will disappear it when you will close your JVM. For your concrete enviroment, with multiples pods, you need a cluster-aware cache implementation. You can't rely on cache implementations based on in-memory storage.

So, you should check out implementations like Spring Redis Cache, which is a cluster-aware cache implementation, and configure it in all your pods.

like image 135
BeardOverflow Avatar answered Dec 04 '25 08:12

BeardOverflow



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!