This PR adds a new method GetOrSet to handle the case where we run into a race when multiple threads do "if not found then set" sequence. Without using GetOrSet, callers will have to use global locks, then perform 1-2 cache operations (Add followed by Get if already exists) which would be redundant and inefficient.
There was a similar PR #82 but it tried to do it using a closure instead of a simple value. This PR takes a much simpler approach to avoid potential long held locks by external code.
This PR adds a new method
GetOrSet
to handle the case where we run into a race when multiple threads do "if not found then set" sequence. Without usingGetOrSet
, callers will have to use global locks, then perform 1-2 cache operations (Add
followed byGet
if already exists) which would be redundant and inefficient.There was a similar PR #82 but it tried to do it using a closure instead of a simple value. This PR takes a much simpler approach to avoid potential long held locks by external code.