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);
转载于:https://www.cnblogs.com/maijin/p/7049355.html
C#缓存absoluteExpiration、slidingExpiration两个参数的疑惑相关推荐
- 文件系统缓存dirty_ratio与dirty_background_ratio两个参数区别
这两天在调优数据库性能的过程中需要降低操作系统文件Cache对数据库性能的影响,故调研了一些降低文件系统缓存大小的方法,其中一种是通过修改/proc/sys/vm/dirty_background_r ...
- cache.get方法的两个参数:key,Callable对象
cache.get方法的两个参数:key,Callable对象 Cache的get方法有两个参数,第一个参数是要从Cache中获取记录的key,第二个记录是一个Callable对象. 当缓存中已经存在 ...
- evt参数是干啥用的_http连接池中非常关键的两个参数,到底是干啥用的?
作者简介:大厂一线资深开发.从crud开发到资深开发,再到研究员兼技术经理.<资深开发讲技术> 从一线实战中总结有故事,有背景的案例,希望带给大家一系列技术盛宴. 求关注,欢迎技术交流.友 ...
- MVC缓存OutPutCache学习笔记 (一) 参数配置
OutPutCache 参数详解 Duration : 缓存时间,以秒为单位,这个除非你的Location=None,可以不添加此属性,其余时候都是必须的. Location : 缓存放置的位置; 该 ...
- ACMNO.30 C语言-宏交换 定义一个带参的宏,使两个参数的值互换,并写出程序,输入两个数作为使用宏时的实参。输出已交换后的两个值。
题目描述 定义一个带参的宏,使两个参数的值互换,并写出程序,输入两个数作为使用宏时的实参.输出已交换后的两个值. 输入 两个数,空格隔开 输出 交换后的两个数,空格隔开 样例输入 1 2 样例输出 2 ...
- 定义一个有参宏SWAP(t,x,y),用以交换t类型的两个参数的值
<程序设计基础-c语言>杨莉 刘鸿翔 ISBN-978-7-03-032903-5 p241 习题7 11.定义一个有参宏SWAP(t,x,y),用以交换t类型的两个参数的值 #inclu ...
- 有监督学习的算法fit(x,y)传两个参数无监督学习的算法是fit(x),即传一个参数
有监督学习的算法fit(x,y)传两个参数无监督学习的算法是fit(x),即传一个参数 https://www.jianshu.com/p/55e261ce9b3e
- wParam和lParam两个参数到底是什么意思?
在Windows的消息函数中,有两个非常熟悉的参数:wParam,lParam. 这两个参数的字面意义对于现在的程序来说已经不重要了,因为它是16位系统的产物,为了保持程序的可移植性,就将它保存了下来 ...
- 利用进化算法+多进程/多线程来优化SVM中的两个参数:C和Gamma
该案例展示了如何利用进化算法+多进程/多线程来优化SVM中的两个参数:C和Gamma. 在执行本案例前,需要确保正确安装sklearn,以保证SVM部分的代码能够正常执行. 本函数需要用到一个外部数据 ...
最新文章
- 前端解决跨域问题的8种方案(最新最全)
- python在windows的开发环境_Python合集之Python开发环境在Windows系统里面搭建
- 腾讯的一笔画游戏--巧妙解法
- 求整数的和与均值(信息学奥赛一本通-T1061)
- Design pattern
- 在linux中写php语言吗,将PHP作为Shell脚本语言使用
- dajngo3新建app,并且访问
- webpack2中postcss-loader报错noconfigfound
- Linux下Qt使用QAudio相关类进行音频采集,使用Windows下的Matlab软件播放
- arm 嵌入式系统复习大纲
- 红宝书背诵笔记 — 必考词
- python怎么下载panda包_pandas python下载
- 正则Regester
- word到处html分页,请问如何把做好的word分页导出为html格式
- 【English】十大词性之感叹词(感叹句)
- 大宗物资采购和运销-煤炭/钢铁/物流数据资源
- 无法访问计算机无效的语法,您输入的表达式包含无效语法(The expression you entered contains invalid syntax)...
- ps把下一幅画透到上一幅去_一千字值得一幅画
- 南邮ctf-密码学(前五题)
- 【程序员眼中的统计学(4)】离散概率分布的运用:善用期望
热门文章
- android调用fragment的方法,AndroidX下使用Activity和Fragment的变化
- 个人对于MySQL的理解_MySQL锁的理解
- 2008r装mysql_RMySQL安装及操作(详细版)
- java 多个 panel_java – 在JFrame中组织多个JPanel的好方法是...
- 不愿意和别人打交道_始终和人保持距离,最不合群的3星座,孤僻却有真本事,能成大事...
- 武汉理工大学计算机学院2018复试,武汉理工大学2018年自主招生复试揭秘
- c调用python gensim包_Jupyter Notebooks嵌入Excel并使用Python替代VBA宏
- ehcache使用_Java 程序员如何使用 Shiro 框架
- 美国留学计算机 奖学金,美国留学 计算机专业奖学金申请解析
- 2016宁波计算机程序复赛,宁波第31届中小学生计算机程序设计竞赛复赛试题小学组.PDF...