Exemple #1
0
        protected override CachePolicy CreateCachePolicy(ControllerContext context, ActionDescriptor action, IDictionary <string, object> parameters)
        {
            var httpMethod = context.HttpContext.Request.HttpMethod;

            if (!httpMethod.EqualsIgnoreCase("get") && !httpMethod.EqualsIgnoreCase("header"))//如果不是GET或Header请求,都不予缓存。
            {
                return(null);
            }


            //如果存在 Cacheable 筛选器,则不再提供默认策略。
            if (action.GetCustomAttributes(typeof(CacheableAttribute), true).Any() || action.ControllerDescriptor.GetCustomAttributes(typeof(CacheableAttribute), true).Any())
            {
                return(null);
            }

            ControllerCachePolicyProvider provider;

            if (ControllerCachePolicyProvider.Providers.TryGetValue(action.ControllerDescriptor.ControllerName, out provider))
            {
                var policy = provider.CreateCachePolicy(context, action, parameters);
                if (policy != null)
                {
                    return(policy);
                }
            }


            return(MvcEnvironment.CreateCachePolicy(context, action, parameters));
        }
Exemple #2
0
        /// <summary>
        /// 引发 ViewCreated 事件
        /// </summary>
        /// <param name="e"></param>
        protected virtual void OnViewCreated(JumonyViewEventArgs e)
        {
            if (ViewCreated != null)
            {
                ViewCreated(this, e);
            }

            MvcEnvironment.OnViewCreated(this, e);
        }
        /// <summary>
        /// 获取缓存策略
        /// </summary>
        /// <param name="context">MVC 请求上下文</param>
        /// <returns></returns>
        protected override CachePolicy CreateCachePolicy(ControllerContext context, ActionDescriptor action, IDictionary <string, object> parameters)
        {
            if (CachePolicyProvider != null)
            {
                return(CachePolicyProvider.CreateCachePolicy(context, action, parameters));
            }



            var httpMethod = context.HttpContext.Request.HttpMethod;

            if (!httpMethod.EqualsIgnoreCase("get") && !httpMethod.EqualsIgnoreCase("header"))//如果不是GET或Header请求,都不予缓存。
            {
                return(null);
            }


            var provider = context.Controller as IMvcCachePolicyProvider;

            if (provider == null)
            {
                var _provider = context.Controller as ICachePolicyProvider;
                if (_provider != null)
                {
                    provider = new MvcCachePolicyProviderWrapper(_provider);
                }
            }

            var policy = provider.CreateCachePolicy(context, action, parameters);

            if (policy != null)
            {
                return(policy);
            }



            return(MvcEnvironment.CreateCachePolicy(context, action, parameters));
        }
 public void Preload(string[] parameters)
 {
     MvcEnvironment.WarmUp();
 }
Exemple #5
0
 /// <summary>
 /// 派生类调用此方法加载虚拟路径处的文档
 /// </summary>
 /// <returns></returns>
 protected virtual IHtmlDocument LoadDocument()
 {
     return(MvcEnvironment.LoadDocument(HttpContext, VirtualPath));
 }