I have a function which Get the value from API and then update inside the cache.
This function is used by all users but I do not want to update the value to cache multiple times. how to avoid multiple writes ? how to take locks for multiple users (if it is possible)? if lock is taken by user A
user B
should not be blocked and continue to update the value and take its own lock. All request for A
should be updated only once to the cache.
Void foo(Guid userId){
bool isFound = GetfromCache(userId);
if(!isFound)
var val = GetValueFromAPI();
UpdateInsideCache(val, userId); // Here we could have multiple requests updating the same entry, since it is high scale system ~ Assume 100 Million request per day.
}