For starters let me just throw it out there that I know the code below is not thread safe (correction: might be). What I am struggling with is finding an implementation that
The cache is threadsafe, but like others have stated, its possible that GetOrAdd will call the func multiple types if call from multiple types.
Here is my minimal fix on that
private readonly SemaphoreSlim _cacheLock = new SemaphoreSlim(1);
and
await _cacheLock.WaitAsync();
var data = await _cache.GetOrCreateAsync(key, entry => ...);
_cacheLock.Release();