zoukankan      html  css  js  c++  java
  • MVC 缓存

    在MVC4中,要启动缓存方法是需要在Action前加上OutputCache特性。

    一、如何使用

    /// <summary>
            /// 公司简介
            /// </summary>
            /// <returns></returns>
            [OutputCache(Duration = 10,Location = OutputCacheLocation.ServerAndClient,VaryByParam = "id")]
            public ActionResult Index(string id)
    Duration:设置或获取缓存时间,单位:秒
    Location:获取或设置缓存的位置。Any(为默认)、 Client、Downstream、 Server、 None、 ServerAndClient

    VaryByParam:缓存依赖,设置或获取缓存基于参数变化的值。        可以根据用户请求的参数来决定是否读取缓存,这个参数主要指的就是QueryString。例如company/index?id=06E6,你的id是变化的,你是希望根据不同的id缓存不同的值。



    二、使用方法二
    这个是ASP.NET4.0出来的一个方法,根据Config配置文件来配置Cache在System.Web下
    <caching>
                <outputCacheSettings>
                    <outputCacheProfiles>
                        <add name="CacheFile"  duration="3600" varyByParam="id"/>
                    </outputCacheProfiles>
                </outputCacheSettings>
            </caching>

    一的方法可以改成

    /// <summary>
            /// 公司简介
            /// </summary>
            /// <returns></returns>
            [OutputCache(CacheProfile = "CacheFile")]
  • 相关阅读:
    Java对于私有变量“反思暴力”技术
    图形界面汇总
    【j2ee spring】27、巴巴荆楚网-整合hibernate4+spring4(2)
    .net Work Flow 4.0
    Drainage Ditches
    Google 开源项目的风格指南
    2015第53周一
    2015第52周日
    2015第52周六
    2015第52周五
  • 原文地址:https://www.cnblogs.com/PEPE/p/3777472.html
Copyright © 2011-2022 走看看