public async Task UpdateEntryAsync(CacheContent content) { var entry = content.CacheEntry; InMemoryCacheEntry inMemoryCacheEntry = null; if (!_responseCache.ContainsKey(entry.Key)) { inMemoryCacheEntry = new InMemoryCacheEntry(entry); lock (syncRoot) { _responseCache[entry.Key] = inMemoryCacheEntry; } } else { inMemoryCacheEntry = _responseCache[entry.Key]; } var newContent = await CloneAsync(content); lock (syncRoot) { inMemoryCacheEntry.Responses[content.Key] = newContent; } }
public static CacheQueryResult Revalidate(CacheContent cacheContent) { return new CacheQueryResult() { Status = CacheStatus.Revalidate, SelectedVariant = cacheContent }; }
public static CacheQueryResult ReturnStored(CacheContent cacheContent) { return new CacheQueryResult() { Status = CacheStatus.ReturnStored, SelectedVariant = cacheContent }; }
public static CacheQueryResult Revalidate(CacheContent cacheContent) { return(new CacheQueryResult() { Status = CacheStatus.Revalidate, SelectedVariant = cacheContent }); }
public static CacheQueryResult ReturnStored(CacheContent cacheContent) { return(new CacheQueryResult() { Status = CacheStatus.ReturnStored, SelectedVariant = cacheContent }); }
private async Task <CacheContent> CloneAsync(CacheContent cacheContent) { var newResponse = new HttpResponseMessage(cacheContent.Response.StatusCode); var ms = new MemoryStream(); foreach (var v in cacheContent.Response.Headers) { newResponse.Headers.TryAddWithoutValidation(v.Key, v.Value); } if (cacheContent.Response.Content != null) { var objectContent = cacheContent.Response.Content as ObjectContent; if (objectContent != null && objectContent.Value != null) { newResponse.Content = new ObjectContent(objectContent.Value.GetType(), objectContent.Value, BaseClient.CreateMediaTypeFormatter()); } else { await cacheContent.Response.Content.CopyToAsync(ms).ConfigureAwait(false); ms.Position = 0; newResponse.Content = new StreamContent(ms); foreach (var v in cacheContent.Response.Content.Headers) { newResponse.Content.Headers.TryAddWithoutValidation(v.Key, v.Value); } } } var newContent = new CacheContent() { CacheEntry = cacheContent.CacheEntry, Key = cacheContent.Key, Expires = cacheContent.Expires, HasValidator = cacheContent.HasValidator, CacheControl = cacheContent.CacheControl, Response = newResponse }; return(newContent); }
private async Task<CacheContent> CloneAsync(CacheContent cacheContent) { var newResponse = new HttpResponseMessage(cacheContent.Response.StatusCode); var ms = new MemoryStream(); foreach (var v in cacheContent.Response.Headers) { newResponse.Headers.TryAddWithoutValidation(v.Key, v.Value); } if (cacheContent.Response.Content != null) { var objectContent = cacheContent.Response.Content as ObjectContent; if (objectContent != null && objectContent.Value != null) { newResponse.Content = new ObjectContent(objectContent.Value.GetType(), objectContent.Value, BaseClient.CreateMediaTypeFormatter()); } else { await cacheContent.Response.Content.CopyToAsync(ms).ConfigureAwait(false); ms.Position = 0; newResponse.Content = new StreamContent(ms); foreach (var v in cacheContent.Response.Content.Headers) { newResponse.Content.Headers.TryAddWithoutValidation(v.Key, v.Value); } } } var newContent = new CacheContent() { CacheEntry = cacheContent.CacheEntry, Key = cacheContent.Key, Expires = cacheContent.Expires, HasValidator = cacheContent.HasValidator, CacheControl = cacheContent.CacheControl, Response = newResponse }; return newContent; }
public async Task UpdateContentAsync(HttpResponseMessage notModifiedResponse, CacheContent cacheContent) { var newExpires = GetExpireDate(notModifiedResponse); if (newExpires > cacheContent.Expires) { cacheContent.Expires = newExpires; } //TODO Copy headers from notModifiedResponse to cacheContent await _contentStore.UpdateEntryAsync(cacheContent); }