コード例 #1
0
        /// <summary>
        /// Occurs before the action method is invoked.
        /// If cached key exist, the actionContext.Response is assigned with the cached data.
        /// When actionContext.Response is not null, the OnActionExecuted will not run.
        /// </summary>
        public override void OnActionExecuting(HttpActionContext actionContext)
        {
            var mainKey    = actionContext.Request.RequestUri.ToString();
            var authHeader = actionContext.Request.Headers.Authorization;
            var key        = ConstructKeyBasedOnAuthorizationHeader(mainKey, authHeader);

            if (cache.DoesKeyExist(key))
            {
                var value   = cache.Get <string>(key);
                var content = new StringContent(value);

                content.Headers.ContentType    = GetContentType(key);
                actionContext.Response         = actionContext.Request.CreateResponse();
                actionContext.Response.Content = content;
            }
        }