0

Can we have a shared cache between 2 different spring boot applications? Both applications should see the same data and when cache is invalidated at one application, the other application should also not see that data in the cache.

Hazelcast can be used across multiple nodes of same application but can it be used across different application? Or is there some other caching that can be used for this.

Praveen
  • 11
  • 6
  • Absolutely fine if the different application services can handle the lifecycle of cached values. In case if you want to make a comparison between Redis vs Hazelcast here is a SO link https://stackoverflow.com/questions/4109366/redis-vs-hazelcast – null Sep 12 '21 at 06:12
  • Can you explain more about the reason, why you want a shared cache between applications? You will tightly couple them together. This sounds awkward to me and I would like to understand your problem to be able to give you the correct advice. – McPringle Sep 12 '21 at 06:35
  • We have 2 applications which refers to the same db table to validate user roles. I want to cache the user roles after the first time it’s fetched from db and want to invalidate the user role cache when one of the application modifies the user roles table. So if the cache is not shared then each application will be referring to separate version of the cache and it will be difficult to invalidate the cache. – Praveen Sep 12 '21 at 16:16
  • That sounds like you should take a look at events. Modifying the role of a user could publish e.g. a `RoleChangedEvent` and all interested applications can subscribe to that kind of event. If the event contains the user, you do not need to invalidate the whole cache. – McPringle Sep 12 '21 at 16:19
  • Usually, the roles are read from DB when the user logs in. That is not often enough to manage a cache for this kind of data. – McPringle Sep 12 '21 at 16:21

0 Answers0