Krishna Kumar
Krishna Kumar

Reputation: 511

How to refresh only near cache in hazelcast

I am new to hazelcast and using it for shared Cache.

We have two nodes which are using shared cache.

Now, we are having one API exposed which will refresh the shared cache on one node, but, we need to refresh the near cache on each node.

If we want to refresh the shared cache, we will get the cache, clear it and repopulate it.

But, I am not sure how to refresh only the near cache.

Basically, I want to refresh the shared cache from the node where the API is being hit, so it will refresh the near cache as well on that node. And only need to refresh near cache of the other node.

Can someone please let me know if we can refresh only near cache without refreshing the complete shared cache and how to do it with example?

Thanks in advance for your help.

Upvotes: 1

Views: 3525

Answers (2)

A.K.Desai
A.K.Desai

Reputation: 1294

NearCache just holds the value for that key in it's local cache after first get request until it is invalidated or timed out. If you are updating the key-value, it gets sync'ed with the cluster.
You can't refresh the NearCache entries alone, that contradicts the very purpose of Distributed Cache.

<!--
Should the cached entries get evicted if the entries are changed (updated or removed).
true of false. Default is true.
-->
<invalidate-on-change>true</invalidate-on-change>

As long as the above property is true(which is by default, if you have not added it to config), the NearCache entries on the other node will get the refreshed data whenever the key is being hit in the subsequent call.

Upvotes: 1

sertug
sertug

Reputation: 969

you don't need to manage near cache manually, you can just make sure you have set <invalidate-on-change> to true in near cache config. It specifies whether the cached entries should be evicted when the entries are updated or removed on the original cache. Its default value is true.

Upvotes: 3

Related Questions