Пример #1
0
        public async Task AddEntryAsync(CacheEntry entry, HttpResponseMessage response)
        {
            CacheEntryContainer cacheEntryContainer = GetOrCreateContainer(entry.Key);

            lock (syncRoot)
            {
                cacheEntryContainer.Entries.Add(entry);
                _responseCache[entry.VariantId] = response;
            }
        }
Пример #2
0
        public async Task UpdateEntryAsync(CacheEntry entry, HttpResponseMessage response)
        {
            CacheEntryContainer cacheEntryContainer = GetOrCreateContainer(entry.Key);

            lock (syncRoot)
            {
                var oldentry = cacheEntryContainer.Entries.First(e => e.VariantId == entry.VariantId);
                cacheEntryContainer.Entries.Remove(oldentry);
                cacheEntryContainer.Entries.Add(entry);
                _responseCache[entry.VariantId] = response;
            }
        }
Пример #3
0
        private CacheEntryContainer GetOrCreateContainer(CacheKey key)
        {
            CacheEntryContainer cacheEntryContainer;

            if (!_CacheContainers.ContainsKey(key))
            {
                cacheEntryContainer = new CacheEntryContainer(key);
                lock (syncRoot)
                {
                    _CacheContainers[key] = cacheEntryContainer;
                }
            }
            else
            {
                cacheEntryContainer = _CacheContainers[key];
            }
            return(cacheEntryContainer);
        }
        private CacheEntryContainer GetOrCreateContainer(CacheKey key)
        {
            CacheEntryContainer cacheEntryContainer;

            if (!_CacheContainers.ContainsKey(key))
            {
                cacheEntryContainer = new CacheEntryContainer(key);
                lock (syncRoot)
                {
                    _CacheContainers[key] = cacheEntryContainer;
                }
            }
            else
            {
                cacheEntryContainer = _CacheContainers[key];
            }
            return cacheEntryContainer;
        }