Beispiel #1
0
        public override void OnActionExecuted(HttpActionExecutedContext axctxt)
        {
            var ctxt = axctxt.ActionContext;

            if (axctxt.Response != null && !axctxt.Response.IsSuccessStatusCode)
            {
                return;
            }
            if (ctxt.Request.Method != HttpMethod.Post &&
                ctxt.Request.Method != HttpMethod.Put &&
                ctxt.Request.Method != HttpMethod.Delete)
            {
                return;
            }

            var controller = ctxt.ControllerContext.ControllerDescriptor;
            var actions    = FindAllGetMethods(controller.ControllerType, TryMatchType ? ctxt.ActionDescriptor.GetParameters() : null);

            var config = ctxt.Request.GetConfiguration();

            EnsureCache(config, ctxt.Request);

            foreach (var action in actions)
            {
                var key = BaseCacheKeyGenerator.GetKey(controller.ControllerName, action);
                if (WebApiCache.Contains(key))
                {
                    WebApiCache.RemoveStartsWith(key);
                }
            }
        }
        public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
        {
            if (actionExecutedContext.Response != null && !actionExecutedContext.Response.IsSuccessStatusCode)
            {
                return;
            }
            _controller = _controller ?? actionExecutedContext.ActionContext.ControllerContext.ControllerDescriptor.ControllerName; // compare: ...ControllerDescriptor.ControllerType.FullName;

            EnsureCache(actionExecutedContext.Request.GetConfiguration(), actionExecutedContext.Request);

            //axctxt.Request.GetConfiguration().CacheOutputConfiguration()
            var basekey = BaseCacheKeyGenerator.GetKey(_controller, _methodName, actionExecutedContext.ActionContext.ActionArguments, BaseKeyCacheArgs);

            if (WebApiCache.Contains(basekey)) // is this a waste? pry not needed, so long as remove gracefully handles a non-existent key
            {
                WebApiCache.RemoveStartsWith(basekey);
            }
        }
Beispiel #3
0
 public virtual string GetValue(object val)
 {
     return(BaseCacheKeyGenerator.GetValueStatic(val));
 }
Beispiel #4
0
 public string GetBaseCacheKey(string controller, string action, string baseKeyExtension = null)
 {
     return(BaseCacheKeyGenerator.GetKey(controller, action, baseKeyExtension));
 }
Beispiel #5
0
 public string GetBaseCacheKey(string controller, string action, Dictionary <string, object> actionArgs, params string[] cacheKeyArgs)
 {
     return(BaseCacheKeyGenerator.GetKey(controller, action, actionArgs, cacheKeyArgs));
 }
Beispiel #6
0
        // controller.ActionContext only exists on newer, 5.1+ WebApi versions

        /// <summary></summary>
        /// <param name="cacheKeyActionArgs">
        /// These values will be the same as what was set
        /// for CacheOutput(CacheArgs="..."), though here as separate strings
        /// (not comma separated).</param>
        public string GetBaseCacheKey(HttpActionContext context, params string[] cacheKeyActionArgs)
        {
            return(BaseCacheKeyGenerator.GetKey(controller.ActionContext, cacheKeyActionArgs));
        }