看了很多资料终于搞明白cache中absoluteExpiration,slidingExpiration这两个参数的含义。

absoluteExpiration:用于设置绝对过期时间,它表示只要时间一到就过期,所以类型为System.DateTime,当给这个参数设置了一个时间时,slidingExpiration参数的值就只能为Cache.NoSlidingExpiration,否则出错;

slidingExpiration:用于设置可调过期时间,它表示当离最后访问超过某个时间段后就过期,所以类型为System.TimeSpan,当给这个参数设置了一个时间段时,absoluteExpiration的值就只能为Cache.NoAbsoluteExpiration,否则出错;

两个使用实例

Cache.Add("name",
content, null, System.Web.Caching.Cache.NoAbsoluteExpiration,
TimeSpan.FromMinutes(10), System.Web.Caching.CacheItemPriority.Normal,
null);

Cache.Add("name",
content, null, DateTime.Now.AddMinutes(10),
System.Web.Caching.Cache.NoSlidingExpiration, CacheItemPriority.Normal,
null);

//
        // 摘要:
        //     Inserts an object into the System.Web.Caching.Cache object together with dependencies,
        //     expiration policies, and a delegate that you can use to notify the application
        //     before the item is removed from the cache.
        //
        // 参数:
        //   key:
        //     The cache key that is used to reference the object.
        //
        //   value:
        //     The object to insert into the cache.
        //
        //   dependencies:
        //     The file or cache key dependencies for the item. When any dependency changes,
        //     the object becomes invalid and is removed from the cache. If there are no dependencies,
        //     this parameter contains null.
        //
        //   absoluteExpiration:
        //     The time at which the inserted object expires and is removed from the cache.
        //     To avoid possible issues with local time such as changes from standard time to
        //     daylight saving time, use System.DateTime.UtcNow instead of System.DateTime.Now
        //     for this parameter value. If you are using absolute expiration, the slidingExpiration
        //     parameter must be set to System.Web.Caching.Cache.NoSlidingExpiration.
        //
        //   slidingExpiration:
        //     The interval between the time that the cached object was last accessed and the
        //     time at which that object expires. If this value is the equivalent of 20 minutes,
        //     the object will expire and be removed from the cache 20 minutes after it was
        //     last accessed. If you are using sliding expiration, the absoluteExpiration parameter
        //     must be set to System.Web.Caching.Cache.NoAbsoluteExpiration.
        //
        //   onUpdateCallback:
        //     A delegate that will be called before the object is removed from the cache. You
        //     can use this to update the cached item and ensure that it is not removed from
        //     the cache.
        //
        // 异常:
        //   T:System.ArgumentNullException:
        //     The key, value, or onUpdateCallback parameter is null.
        //
        //   T:System.ArgumentOutOfRangeException:
        //     You set the slidingExpiration parameter to less than TimeSpan.Zero or the equivalent
        //     of more than one year.
        //
        //   T:System.ArgumentException:
        //     The absoluteExpiration and slidingExpiration parameters are both set for the
        //     item you are trying to add to the Cache.-or-The dependencies parameter is null,
        //     and the absoluteExpiration parameter is set to System.Web.Caching.Cache.NoAbsoluteExpiration,
        //     and the slidingExpiration parameter is set to System.Web.Caching.Cache.NoSlidingExpiration.
        public void Insert(string key, object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemUpdateCallback onUpdateCallback);

C#缓存absoluteExpiration、slidingExpiration两个参数的疑惑的更多相关文章

  1. [转载]C#缓存absoluteExpiration、slidingExpiration两个参数的疑惑

    看了很多资料终于搞明白cache中absoluteExpiration,slidingExpiration这两个参数的含义. absoluteExpiration:用于设置绝对过期时间,它表示只要时间 ...

  2. 文件系统缓存dirty_ratio与dirty_background_ratio两个参数区别

    这两天在调优数据库性能的过程中需要降低操作系统文件Cache对数据库性能的影响,故调研了一些降低文件系统缓存大小的方法,其中一种是通过修改/proc/sys/vm/dirty_background_r ...

  3. (转)文件系统缓存dirty_ratio与dirty_background_ratio两个参数区别

    这两天在调优数据库性能的过程中需要降低操作系统文件Cache对数据库性能的影响,故调研了一些降低文件系统缓存大小的方法,其中一种是通过修改/proc/sys/vm/dirty_background_r ...

  4. Linux 文件系统缓存dirty_ratio与dirty_background_ratio两个参数区别

    文件系统缓存dirty_ratio与dirty_background_ratio两个参数区别 (2014-03-16 17:54:32) 转载▼ 标签: linux 文件系统缓存 cache dirt ...

  5. wParam和lParam两个参数到底是什么意思?

    在Windows的消息函数中,有两个非常熟悉的参数:wParam,lParam. 这两个参数的字面意义对于现在的程序来说已经不重要了,因为它是16位系统的产物,为了保持程序的可移植性,就将它保存了下来 ...

  6. 25.按要求编写一个Java应用程序: (1)编写一个矩形类Rect,包含: 两个属性:矩形的宽width;矩形的高height。 两个构造方法: 1.一个带有两个参数的构造方法,用于将width和height属性初化; 2.一个不带参数的构造方法,将矩形初始化为宽和高都为10。 两个方法: 求矩形面积的方法area() 求矩形周长的方法perimeter() (2)通过继承Rect类编写一个具有

    package zhongqiuzuoye; //自己写的方法 public class Rect { public double width; public double height; Rect( ...

  7. MVC缓存OutPutCache学习笔记 (一) 参数配置

    OutPutCache 参数详解 Duration : 缓存时间,以秒为单位,这个除非你的Location=None,可以不添加此属性,其余时候都是必须的. Location : 缓存放置的位置; 该 ...

  8. ci连贯操作的limit两个参数和sql是相反的

    ci连贯操作的limit两个参数和sql是相反的 db->where("name =",'mary')->ge() name后面要有个空格否则报错当为一个字段 -> ...

  9. 三个案例带你看懂LayoutInflater中inflate方法两个参数和三个参数的区别

    关于inflate参数问题,我想很多人多多少少都了解一点,网上也有很多关于这方面介绍的文章,但是枯燥的理论或者翻译让很多小伙伴看完之后还是一脸懵逼,so,我今天想通过三个案例来让小伙伴彻底的搞清楚这个 ...

随机推荐

  1. ECMAScript6 入门 函数的扩展

    为函数参数设定默认值 function log(x, y = 'World') { console.log(x, y); } log('Hello') // Hello World log('Hell ...

  2. ThreadPoolExecutor 入参 corePoolSize 和 maximumPoolSize 的联系

    前言 我们可以通过 java.util.concurrent.ThreadPoolExecutor 来创建一个线程池: new ThreadPoolExecutor(corePoolSize, max ...

  3. SpringMVC(三十) 实例:SpringMVC_RESTRUL_CRUD_显示所有员工信息

    Step by step to create a springMVC demo. 1. 创建一个dynamic web 工程. 2. 添加需要的jar文件,如下图: 3. 配置web.xml:配置di ...

  4. shell编程第四天

  5. 南阳236----心急的C小加

    #include<cstdio> #include<algorithm> #define inf 1<<30 using namespace std; typede ...

  6. Java代码优化小结(一)

    (1)尽量指定类.方法的final修饰符 带有final修饰符的类是不可派生的.在Java核心API中,有许多应用final的例子,例如java.lang.String,整个类都是final的.为类指 ...

  7. git rewinding head to replay your work on top of it...

    git fetch origin git reset --hard origin/<branch>

  8. 潭州课堂25班:Ph201805201 django 项目 第四十六课 查错 补缺 (课堂笔记

    从讲项目开始,查找错误,完善笔记,尽可能 翻译没一句代码(以后台为主), 本项目亮点,也是重点 Django ORM中对数据查询的优化(only.defer.select_related) redis ...

  9. Vue子页面给父页面传递数据

    子页面: <template> <div> <p>子组件</p> <button @click="sendMsg">传递 ...

  10. 获取Gitlab项目的Token

    获取Gitlab项目的Token 1.打开所需要Token的项目的主页进入CI/CD setting Setting -> CI/CD -> Genneral pioelines sett ...