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,我今天想通过三个案例来让小伙伴彻底的搞清楚这个 ...
随机推荐
- spring security学习
https://www.cnblogs.com/leihenqianshang/articles/5313159.html
- 队列queue实现线程的消费者和生产者
import threading import queue import random import time qq = queue.Queue(4) #实例化一个队列,因为是一个进程的线程,所以共资 ...
- bootstrapTable
一个详细的教程 table参数 bootstrap table使用总结 BootstrapTable使用实例 事件event 事件函数的用法: 方法1 $('#table').bootstrapTab ...
- AngularJS之拖拽排序(ngDraggable.js)
ngDraggable.js是一款比较简单实用的angularJS拖拽插件,借助于封装好的一些自定义指令,能够快速的进行一些拖拽应用开发.首先先介绍一些基本的概念; ng-drop:是否允许放入拖拽元 ...
- 平衡二叉树的java实现
转载请注明出处! 一.概念 平衡二叉树是一种特殊的二叉搜索树,关于二叉搜索树,请查看上一篇博客二叉搜索树的java实现,那它有什么特别的地方呢,了解二叉搜索树的基本都清楚,在按顺序向插入二叉搜索树中插 ...
- 使用shiro安全管理
之前介绍了springboot使用security进行权限管理,这篇文件介绍一下springboot使用shiro进行安全管理. 简述本文的场景,本文使用springboot1.5.9+mysql+j ...
- [MySQL] MySQL联表查询的执行顺序优化查询
SELECT t4.orgName, t3.projectName, t3.Partner, t1.type, COUNT(DISTINCT t1.imei) AS count FROM `t_tem ...
- 2017-9-7-Linux Mint TFTP服务安装开启
Linux Mint端安装tftp软件 sudo apt-get install tftpd-hpa // tftpd-hpa是服务器端 sudo apt-get install tftp-hpa / ...
- 2190 ACM 数学概率论的乘法和加法原则
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2190 思路:明显我们要寻找 边长为n和边长为n-1,n-2,n-3·····的规律,这样得出一个递推公式就 ...
- shell脚本8--录制终端会话
准备: script -t 2> timing.log -a output.session type commands; ... . .. exit 回放: scriptreplay timin ...