C#缓存absoluteExpiration、slidingExpiration两个参数的疑惑
看了很多资料终于搞明白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两个参数的疑惑的更多相关文章
- [转载]C#缓存absoluteExpiration、slidingExpiration两个参数的疑惑
看了很多资料终于搞明白cache中absoluteExpiration,slidingExpiration这两个参数的含义. absoluteExpiration:用于设置绝对过期时间,它表示只要时间 ...
- 文件系统缓存dirty_ratio与dirty_background_ratio两个参数区别
这两天在调优数据库性能的过程中需要降低操作系统文件Cache对数据库性能的影响,故调研了一些降低文件系统缓存大小的方法,其中一种是通过修改/proc/sys/vm/dirty_background_r ...
- (转)文件系统缓存dirty_ratio与dirty_background_ratio两个参数区别
这两天在调优数据库性能的过程中需要降低操作系统文件Cache对数据库性能的影响,故调研了一些降低文件系统缓存大小的方法,其中一种是通过修改/proc/sys/vm/dirty_background_r ...
- Linux 文件系统缓存dirty_ratio与dirty_background_ratio两个参数区别
文件系统缓存dirty_ratio与dirty_background_ratio两个参数区别 (2014-03-16 17:54:32) 转载▼ 标签: linux 文件系统缓存 cache dirt ...
- wParam和lParam两个参数到底是什么意思?
在Windows的消息函数中,有两个非常熟悉的参数:wParam,lParam. 这两个参数的字面意义对于现在的程序来说已经不重要了,因为它是16位系统的产物,为了保持程序的可移植性,就将它保存了下来 ...
- 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( ...
- MVC缓存OutPutCache学习笔记 (一) 参数配置
OutPutCache 参数详解 Duration : 缓存时间,以秒为单位,这个除非你的Location=None,可以不添加此属性,其余时候都是必须的. Location : 缓存放置的位置; 该 ...
- ci连贯操作的limit两个参数和sql是相反的
ci连贯操作的limit两个参数和sql是相反的 db->where("name =",'mary')->ge() name后面要有个空格否则报错当为一个字段 -> ...
- 三个案例带你看懂LayoutInflater中inflate方法两个参数和三个参数的区别
关于inflate参数问题,我想很多人多多少少都了解一点,网上也有很多关于这方面介绍的文章,但是枯燥的理论或者翻译让很多小伙伴看完之后还是一脸懵逼,so,我今天想通过三个案例来让小伙伴彻底的搞清楚这个 ...
随机推荐
- sql union 列的字段不一样的时候
- P3353 在你窗外闪耀的星星
飞逝的的时光不会模糊我对你的记忆.难以相信从我第一次见到你以来已经过去了3年.我仍然还生动地记得,3年前,在美丽的集美中学,从我看到你微笑着走出教室,你将头向后仰,柔和的晚霞照耀着你玫瑰色的脸颊.我明 ...
- 双重保险——前端bootstrapValidator验证+后台MVC模型验证
我们在前端使用BoostrapValidator插件验证最基本的格式要求问题,同时在后台中,使用MVC特有的模型验证来做双重保险.对于boostrapValidator我就不说了,具体请看<bo ...
- iOS12系统应用开发发送邮件
iOS12系统应用开发发送邮件 消息分享是应用社交化和营销的重要途径.除了开发者自己搭建专有的消息分享渠道之外,还可以借助系统自带的各种途径.iOS提供了3种快速分享消息的方式,分别为发送邮件.发送短 ...
- 【DWM1000】 code 解密7一ANCHOR接收到BLINK
接着之前ANCHOR的代码分析,但接收到无线数据,应该执行如下代码 case TA_RX_WAIT_DATA : //already recive a message ...
- C++ Primer 与“类”有关的注意事项总结
C++ 与"类"有关的注意事项总结(一) 1. 除了静态 static 数据成员外,数据成员不能在类体中被显式地初始化. 例如 : class First { int memi = ...
- BZOJ5177 : [Jsoi2013]贪心的导游
首先预处理出对于每个模数,所有被模数按结果从大到小排序的结果,那么对于一个询问,如果可以在$O(1)$时间内判断某个数字是否出现,则可以$O(1000)$回答. 考虑对序列进行分治,对于区间$[l,r ...
- MySQL(五)
关系 创建成绩表scores,结构如下 id 学生 科目 成绩 思考:学生列应该存什么信息呢? 答:学生列的数据不是在这里新建的,而应该从学生表引用过来,关系也是一条数据:根据范式要求应该存储学生的编 ...
- shell脚本使用技巧7--cat
cat是单词concatenate缩写 echo 'text through stdin' | cat - file.txt 输出:text throgh stdin 和file.txt中的内容: c ...
- 报错Error configuring application listener of class org.springframework.web.context.ContextConfigLocation
错误内容是ClassNotFoundException: org.springframework.web.context.ContextConfigLocationdao导致一运行项目就是404 是因 ...