[Spike] SetRepositoryCache#fetch atomicity approaches
Why
#506430 describes the race condition that occurs due to this like of atomicity.
Because the issue is complex and requires some extensive coding as well as CI runs to verify feasibility, research is moved into this spike issue.
Once we verify a feasible a solution we can recommend an implementation approach on the original issue.
Approaches
Lua scripts
Originally it was suggested that we solve the problem through atomic lua scripts in the redis calls to resolve the race condition.
The approach was tried here: !179429 (closed)
The primary problem with this approach is that there doesn't seem to be a good way to avoid having to yield the block every time to pass the result to the Lua script. This defeats the purpose of caching.
Checking cache again after yield block
This might solve one set of race conditions but leave another set, and therefor was not considered robust enough to be considered further.
The approach was tried here: !179626 (closed)
Redis WATCH
A proof of concept was suggested and needs further investigation.