コード例 #1
0
        /// <summary>
        /// Action to occur after the action method is invoked
        /// </summary>
        /// <param name="actionExecutedContext">The action executed context</param>
        public override void OnActionExecuted(
            HttpActionExecutedContext actionExecutedContext)
        {
            actionExecutedContext.NotNull(nameof(actionExecutedContext));

            if (!actionExecutedContext.IsASuccessfulResponse())
            {
                return;
            }

            if (!IsCachingAllowed(actionExecutedContext.ActionContext))
            {
                return;
            }

            if (CacheTime.AbsoluteExpirationTime <= _nowFactory())
            {
                return;
            }

            var cacheKey = GetCacheKey(actionExecutedContext.ActionContext);

            if (cacheKey.IsNullOrEmpty() ||
                ExistsItemInCache(actionExecutedContext, cacheKey) ||
                actionExecutedContext.Response.Content.IsNull())
            {
                return;
            }

            StoreContent(actionExecutedContext, cacheKey);

            ApplyCacheHeaders(actionExecutedContext.Response);
        }
コード例 #2
0
        public static bool IsASuccessfulResponse(
            this HttpActionExecutedContext actionExecutedContext)
        {
            actionExecutedContext.NotNull(nameof(actionExecutedContext));

            return(actionExecutedContext.ActionContext.Response.IsNotNull() &&
                   actionExecutedContext.ActionContext.Response.IsSuccessStatusCode);
        }
コード例 #3
0
        /// <summary>
        /// Action to occur after the action method is invoked
        /// </summary>
        /// <param name="actionExecutedContext">The action executed context</param>
        public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
        {
            actionExecutedContext.NotNull(nameof(actionExecutedContext));

            if (!actionExecutedContext.IsASuccessfulResponse())
            {
                return;
            }

            if (!IsCachingAllowed(actionExecutedContext.ActionContext))
            {
                return;
            }

            if (actionExecutedContext.Response.Content.IsNull())
            {
                return;
            }

            ApplyCacheHeaders(actionExecutedContext.Response);
        }