public async Task<IEnumerable<CacheEntry>> GetEntriesAsync(CacheKey cacheKey) { if (_CacheContainers.ContainsKey(cacheKey)) { return _CacheContainers[cacheKey].Entries; } return null; }
public CacheEntry(CacheKey key, HttpResponseMessage response) { Key = key; Vary = response.Headers.Vary.Select(v=> v.ToLowerInvariant()).ToList(); ResponseVaryHeaders = response.RequestMessage.Headers .Where(h => Vary.Contains(h.Key.ToLowerInvariant())) .ToDictionary(k => k.Key.ToLowerInvariant(), v => v.Value); VariantId = Guid.NewGuid(); HasValidator = response.Headers.ETag != null || (response.Content != null && response.Content.Headers.LastModified != null); CacheControl = response.Headers.CacheControl ?? new CacheControlHeaderValue(); }
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; }
public async Task StoreResponseAsync(HttpResponseMessage response) { var primaryCacheKey = new CacheKey(response.RequestMessage.RequestUri, response.RequestMessage.Method); CacheEntry selectedEntry = null; IEnumerable<CacheEntry> cacheEntries = await _contentStore.GetEntriesAsync(primaryCacheKey).ConfigureAwait(false); if (cacheEntries != null) { selectedEntry = MatchVariant(response.RequestMessage, cacheEntries); } if (selectedEntry != null) { UpdateCacheEntry(response, selectedEntry); await _contentStore.UpdateEntryAsync(selectedEntry, response).ConfigureAwait(false); } else { selectedEntry = new CacheEntry(primaryCacheKey, response); UpdateCacheEntry(response, selectedEntry); await _contentStore.AddEntryAsync(selectedEntry, response).ConfigureAwait(false); } }
public CacheEntryContainer(CacheKey primaryCacheKey) { PrimaryCacheKey = primaryCacheKey; Entries = new List<CacheEntry>(); }