Domanda

We were maintaining the cache using ConcurrentHashMap Often times the cache needs to be refreshed What is the bestway to refresh the cache?

1.Update the cache , Remove all stale keys.

2.Clear the cache and insert fresh keys again from the content.

Case 1: all read threads will not be blocked, once updated they will get the updated value.

Case 2: Here my question what will happen to read threads when we will clear the cache?Do they get null value ?

What is the best strategy to update the cache?

È stato utile?

Soluzione

Most reliable answer as usual is in API, which for this situation says ... For aggregate operations such as putAll and clear, concurrent retrievals may reflect insertion or removal of only some entries...

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top