private ProfileElement getWebApiCacheProfile()
        {
            var            webApiCacheConfig    = WebApiCacheConfigSection.GetConfig();
            ProfileElement webApiProfileElement = null;

            if (webApiCacheConfig != null && webApiCacheConfig.Profiles != null && webApiCacheConfig.Profiles.Count > 0)
            {
                webApiProfileElement = webApiCacheConfig.Profiles[CacheProfile];
            }
            return(webApiProfileElement);
        }
        public async override Task OnActionExecutingAsync(HttpActionContext actionContext, CancellationToken cancellationToken)
        {
            if (actionContext == null)
            {
                throw new ArgumentNullException("actionContext");
            }

            ProfileElement webApiProfileElement = null;

            webApiProfileElement = getWebApiCacheProfile();
            if (webApiProfileElement != null && webApiProfileElement.Enable)
            {
                this.ClientTimeSpan = webApiProfileElement.ClientTimeSpan;
                this.ServerTimeSpan = webApiProfileElement.ServerTimeSpan;
                this.MustRevalidate = webApiProfileElement.MustRevalidate;
                this.ExcludeQueryStringFromCacheKey = webApiProfileElement.ExcludeQueryStringFromCacheKey;
                this.AnonymousOnly = webApiProfileElement.AnonymousOnly;
            }
            //是否允许缓存
            if (!IsCachingAllowed(actionContext, AnonymousOnly))
            {
                return;
            }

            var config = actionContext.Request.GetConfiguration();

            EnsureCacheTimeQuery();
            EnsureCache(config, actionContext.Request);
            //Key
            var cacheKeyGenerator = config.CacheOutputConfiguration().GetCacheKeyGenerator(actionContext.Request, CacheKeyGenerator);
            //返回值类型
            var responseMediaType = GetExpectedMediaType(config, actionContext);

            actionContext.Request.Properties[CurrentRequestMediaType] = responseMediaType;
            //生成Key
            var cachekey = cacheKeyGenerator.MakeCacheKey(actionContext, responseMediaType, ExcludeQueryStringFromCacheKey);

            if (!_webApiCache.Contains(cachekey))
            {
                return;
            }
            //ETag判断
            if (actionContext.Request.Headers.IfNoneMatch != null)
            {
                var etag = _webApiCache.Get <string>(cachekey + Constants.EtagKey);
                if (etag != null)
                {
                    if (actionContext.Request.Headers.IfNoneMatch.Any(x => x.Tag == etag))
                    {
                        var time          = CacheTimeQuery.Execute(DateTime.Now);
                        var quickResponse = actionContext.Request.CreateResponse(HttpStatusCode.NotModified);
                        ApplyCacheHeaders(quickResponse, time);
                        //输出
                        actionContext.Response = quickResponse;
                        return;
                    }
                }
            }
            //直接从缓存返回
            var val = _webApiCache.Get <byte[]>(cachekey);

            if (val == null)
            {
                return;
            }

            var contenttype = _webApiCache.Get <MediaTypeHeaderValue>(cachekey + Constants.ContentTypeKey) ?? new MediaTypeHeaderValue(cachekey.Split(new[] { ':' }, 2)[1].Split(';')[0]);

            actionContext.Response         = actionContext.Request.CreateResponse();
            actionContext.Response.Content = new ByteArrayContent(val);

            actionContext.Response.Content.Headers.ContentType = contenttype;
            var responseEtag = _webApiCache.Get <string>(cachekey + Constants.EtagKey);

            if (responseEtag != null)
            {
                SetEtag(actionContext.Response, responseEtag);
            }

            var cacheTime = CacheTimeQuery.Execute(DateTime.Now);

            ApplyCacheHeaders(actionContext.Response, cacheTime);

            //判断是否需要预读
            if (PreloadAllowed(actionContext))
            {
                await PreloadNextPageByHttpClient(actionContext);
            }
        }