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,我今天想通过三个案例来让小伙伴彻底的搞清楚这个 ...
随机推荐
- 总结几种清除浏览器的缓存,适用于明明已经修改bug,但是测试人员说问题还存在的情况下
1.meta方法<METAHTTP-EQUIV="pragma"CONTENT="no-cache"><METAHTTP-EQUIV=&quo ...
- 【python】数据库
No1: [SQLite] 插入 # 导入SQLite驱动: >>> import sqlite3 # 连接到SQLite数据库 # 数据库文件是test.db # 如果文件不存在, ...
- photoshop实现倾斜图片的修正
第一天学习Photoshop,了解到了Photoshop对图片的处理,下面是实现一个倾斜图片修正的两种方法: 举例图片: 第一种方法:1.利用吸管中的标尺工具量倾斜度数: 2.利用旋转图像,旋转对应的 ...
- jquery中,使用append增加新元素时,新增元素的绑定监听事件失效的解决办法
$("outerSelector").on("eventType","innerSelector",function(){}); 举例:如果 ...
- Saltstack报错小记
这是之前的一篇文章,由于有小伙伴也遇到同样的错误,就拿出来分享下吧 [root@master ~]# salt 'minion.saltstack.com' state.sls init.pkg[ER ...
- excel计算时间差值
excel计算时间差值 2018/10/1 10:59:00 减去 2018/9/21 1:05:13 获取 多少天. 如1.2天.这种. ==
- 2017-9-10-Vim使用说明
首先,很多linux发行版直接进入的是vi,不是vim,刚开始使用vi会有点蒙,需要改一下配置文件到vim:"打开vi编辑器,输入i,左下角没有出现-INSERT-字样,且编辑模式跟vim不 ...
- [ONTAK2015]Tasowanie
[ONTAK2015]Tasowanie 题目大意: 给你两个长度分别为\(n(n\le2\times10^5)\)的序列\(A,B\),将\(A,B\)进行二路归并,使得最后得到的序列字典序最小.求 ...
- [CC-INVENTRY]Arranging the Inventory
[CC-INVENTRY]Arranging the Inventory 题目大意: 有一排长度为\(n(\sum n\le10^6)\)的格子,有些格子是空的,有些格子上有一个箱子. 现在你要用最小 ...
- BZOJ2512 : Groc
最优解一定是将起点.终点以及所有必经点连接成一棵树,对于每条树边恰好走两次,而从起点到终点的一条路径只走一次. 考虑连通性DP,设$f[i][j][k][x]$表示考虑完前$i$个走道,第$i$个走道 ...