public Task <ICacheEntry> GetAsync(string key, CancellationToken ct) { var found = _cache.TryGetValue(key, out ArraySegment <byte> bytes); if (!found) { return(Task.FromResult <ICacheEntry>(new EmptyCacheEntry())); } return(Task.FromResult <ICacheEntry>(new MemoryCacheEntry(bytes))); }
// Calling thread need to be first lock "_lock" private ICacheEntry GetInternal(string key) { var inUse = _inUse.TryGetValue(key, out DiskCacheEntry entry); if (inUse) { return(entry); } var found = _lruCache.TryGetValue(key, out entry); if (found) { // Move from _lruCache to _inUse _lruCache.Remove(key); _inUse.TryAdd(key, entry); return(entry); } else { return(new EmptyCacheEntry()); } }