예제 #1
0
        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)));
        }
예제 #2
0
        // 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());
            }
        }