public override async Task OnActionExecutingAsync(HttpActionContext actionContext, CancellationToken cancellationToken)
{
/*
cache-request-directive =
"no-cache" ; Section 14.9.1
| "no-store" ; Section 14.9.2
| "max-age" "=" delta-seconds ; Section 14.9.3, 14.9.4
| "max-stale" [ "=" delta-seconds ] ; Section 14.9.3
| "min-fresh" "=" delta-seconds ; Section 14.9.3
| "no-transform" ; Section 14.9.5
| "only-if-cached" ; Section 14.9.4
| cache-extension ; Section 14.9.6
*/
var request = actionContext.Request;
var cacheControl = request.Headers.CacheControl;
if (ShouldIgnoreCache(cacheControl, actionContext.Request))
{
return;
}
var scope = request.GetDependencyScope();
var invocation = GetInvocation(actionContext);
var context = GetInvocationContext(actionContext);
var strategy = GetCacheStrategy(scope, invocation, context);
var cacheKey = strategy.CacheKeyProvider.GetCacheKey(invocation, context);
var hashedKey = HashCacheKey(cacheKey);
var cacheStore = strategy.GetAsyncCacheStore(invocation, context);
var storedKey = $"fw-{cacheStore.StoreId}-{hashedKey}";
var builder = GetCacheResponseBuilder(scope);
request.Properties[Global.__flatwhite_outputcache_store] = cacheStore;
request.Properties[Global.__flatwhite_outputcache_key] = storedKey;
request.Properties[Global.__flatwhite_outputcache_strategy] = strategy;
request.Properties[WebApiExtensions.__webApi_outputcache_response_builder] = builder;
var cacheItem = await cacheStore.GetAsync(storedKey).ConfigureAwait(false) as WebApiCacheItem;
if (cacheItem != null && cacheItem.IsStale())
{
if (!Global.Cache.PhoenixFireCage.ContainsKey(storedKey))
{
CreatePhoenix(invocation, cacheItem, actionContext.Request);
}
RefreshCache(storedKey);
}
actionContext.Response = builder.GetResponse(cacheControl, cacheItem, actionContext.Request);
}