Reputation: 1789
I am using hazelCast to cache the data getting fetched from API. Structure of the API is something like this
Controller->Service->DAOLayer->DB
I am keeping @Cacheable at service layer where getData(int elementID) method is present.
In my architecture there are two PaaS nodes (np3a, np4a). API will be deployed on both of them and users will be accessing them via loadBalancer IP, which will redirect them to either of the nodes.
So It might be possible that for one hit from User X request goes to np3a and for another hit from same user request goes to np4a.
I want that in the very first hit when I would be caching the response on np3a, the same cached response is also available for next hit to np4a.
I have read about
I am not sure which one approach to take or if you suggest something entirely different.
Upvotes: 0
Views: 529
Reputation: 1186
If you have 2 nodes, Hazelcast will partition data so that half of it will be on node 1, and the other half on node 2. It means there's a 50% chance a user will ask the node containing the data.
If you want to avoid in all cases an additional network request to fetch data that is not present on a node, the only way is to copy data each time to every node. That's the goal of ReplicatedMap
. That's the trade-off: performance vs. memory consumption.
NearCache
adds an additional cache on the "client-side", if you're using client-server architecture (as opposed to embedded).
Upvotes: 1