Java Docs says that, putIfAbsent is equivalent to
if (!map.containsKey(key))
return map.put(key, value);
else
return map.get(key);
So if the key exists in the map, it doesn't update its value. Is this correct?
What if i want to update a keys value based on some criteria? Say expiration time etc.
Would this be a better impl for adding and updating cache?
public void AddToCache(T key, V value)
{
V local = _cache.putifabsent(key, value);
if(local.equals(value) && local.IsExpired() == false){
return;
}
// this is for updating the cache with a new value
_cache.put(key, value);
}