Removing double casts
This commit is contained in:
Родитель
48abc69b1a
Коммит
1571a2dbe9
|
@ -27,4 +27,5 @@ nuget.exe
|
|||
project.lock.json
|
||||
/.vs/
|
||||
.build/
|
||||
.testPublish/
|
||||
.testPublish/
|
||||
launchSettings.json
|
|
@ -24,11 +24,11 @@ namespace Microsoft.AspNetCore.ResponseCaching.Internal
|
|||
public Task<IResponseCacheEntry> GetAsync(string key)
|
||||
{
|
||||
var entry = _cache.Get(key);
|
||||
|
||||
if (entry is MemoryCachedResponse)
|
||||
|
||||
var memoryCachedResponse = entry as MemoryCachedResponse;
|
||||
if (memoryCachedResponse != null)
|
||||
{
|
||||
var memoryCachedResponse = (MemoryCachedResponse)entry;
|
||||
return Task.FromResult<IResponseCacheEntry>(new CachedResponse()
|
||||
return Task.FromResult<IResponseCacheEntry>(new CachedResponse
|
||||
{
|
||||
Created = memoryCachedResponse.Created,
|
||||
StatusCode = memoryCachedResponse.StatusCode,
|
||||
|
@ -44,15 +44,15 @@ namespace Microsoft.AspNetCore.ResponseCaching.Internal
|
|||
|
||||
public async Task SetAsync(string key, IResponseCacheEntry entry, TimeSpan validFor)
|
||||
{
|
||||
if (entry is CachedResponse)
|
||||
var cachedResponse = entry as CachedResponse;
|
||||
if (cachedResponse != null)
|
||||
{
|
||||
var cachedResponse = (CachedResponse)entry;
|
||||
var segmentStream = new SegmentWriteStream(StreamUtilities.BodySegmentSize);
|
||||
await cachedResponse.Body.CopyToAsync(segmentStream);
|
||||
|
||||
_cache.Set(
|
||||
key,
|
||||
new MemoryCachedResponse()
|
||||
new MemoryCachedResponse
|
||||
{
|
||||
Created = cachedResponse.Created,
|
||||
StatusCode = cachedResponse.StatusCode,
|
||||
|
@ -60,7 +60,7 @@ namespace Microsoft.AspNetCore.ResponseCaching.Internal
|
|||
BodySegments = segmentStream.GetSegments(),
|
||||
BodyLength = segmentStream.Length
|
||||
},
|
||||
new MemoryCacheEntryOptions()
|
||||
new MemoryCacheEntryOptions
|
||||
{
|
||||
AbsoluteExpirationRelativeToNow = validFor
|
||||
});
|
||||
|
@ -70,7 +70,7 @@ namespace Microsoft.AspNetCore.ResponseCaching.Internal
|
|||
_cache.Set(
|
||||
key,
|
||||
entry,
|
||||
new MemoryCacheEntryOptions()
|
||||
new MemoryCacheEntryOptions
|
||||
{
|
||||
AbsoluteExpirationRelativeToNow = validFor
|
||||
});
|
||||
|
|
|
@ -111,8 +111,14 @@ namespace Microsoft.AspNetCore.ResponseCaching
|
|||
}
|
||||
}
|
||||
|
||||
internal async Task<bool> TryServeCachedResponseAsync(ResponseCacheContext context, CachedResponse cachedResponse)
|
||||
internal async Task<bool> TryServeCachedResponseAsync(ResponseCacheContext context, IResponseCacheEntry cacheEntry)
|
||||
{
|
||||
var cachedResponse = cacheEntry as CachedResponse;
|
||||
if (cachedResponse == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
context.CachedResponse = cachedResponse;
|
||||
context.CachedResponseHeaders = new ResponseHeaders(cachedResponse.Headers);
|
||||
context.ResponseTime = _options.SystemClock.UtcNow;
|
||||
|
@ -171,24 +177,26 @@ namespace Microsoft.AspNetCore.ResponseCaching
|
|||
context.BaseKey = _keyProvider.CreateBaseKey(context);
|
||||
var cacheEntry = await _store.GetAsync(context.BaseKey);
|
||||
|
||||
if (cacheEntry is CachedVaryByRules)
|
||||
var cachedVaryByRules = cacheEntry as CachedVaryByRules;
|
||||
if (cachedVaryByRules != null)
|
||||
{
|
||||
// Request contains vary rules, recompute key(s) and try again
|
||||
context.CachedVaryByRules = (CachedVaryByRules)cacheEntry;
|
||||
context.CachedVaryByRules = cachedVaryByRules;
|
||||
|
||||
foreach (var varyKey in _keyProvider.CreateLookupVaryByKeys(context))
|
||||
{
|
||||
cacheEntry = await _store.GetAsync(varyKey);
|
||||
|
||||
if (cacheEntry is CachedResponse && await TryServeCachedResponseAsync(context, (CachedResponse)cacheEntry))
|
||||
if (await TryServeCachedResponseAsync(context, await _store.GetAsync(varyKey)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (cacheEntry is CachedResponse && await TryServeCachedResponseAsync(context, (CachedResponse)cacheEntry))
|
||||
else
|
||||
{
|
||||
return true;
|
||||
if (await TryServeCachedResponseAsync(context, cacheEntry))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (context.RequestCacheControlHeaderValue.OnlyIfCached)
|
||||
|
|
Загрузка…
Ссылка в новой задаче