System.Web.Caching.Cache 的到期时间是多久?

YSEE 2010-11-17 04:56:13
System.Web.Caching.Cache





Cache["aaa"] = "aa";

这样用 的默认到期时间 是?或者 什么时候失效?
...全文
463 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
孟子E章 2010-11-17
  • 打赏
  • 举报
回复
下面是网上的一段文字,讲述了关于 Cache的一些知识

There is some additional information that you should be aware of regarding cache configuration.

* If the worker process private bytes limit is not set, the cache will use one of the following limits:
o x86 2GB: 800MB or 60% of physical RAM, whichever is less
o x86 3GB: 1800MB or 60% of physical RAM, whichever is less
o x64: 1 terabyte or 60% of physical RAM, whichever is less
* If both the worker process private bytes limit and <cache privateBytesLimit/> are set, the cache will use the minimum of the two.
* Just like in 1.x, we drop cache entries and call GC.Collect for two reasons:
o We are very close to the private bytes limit
o The available memory is near or less than 10%
* You can effectively disable trim and cache for low available memory conditions by setting <cache percentagePhysicalMemoryUseLimit/> to 100.
* Unlike 1.x, 2.0 will suspend the trim and collect calls if the last GC.Collect did not reduce private bytes or the size of the managed heaps by more than 1% of the (cache) memory limit.
孟子E章 2010-11-17
  • 打赏
  • 举报
回复
不过,Cache跟内存有关系,所以使用的时候应该先进行判断if(Cache["x"] != null)

另外, .net 4.0的Cache可以自己定义了,可以存储在文件系统中,不受内存的影响
孟子E章 2010-11-17
  • 打赏
  • 举报
回复
不设置就是一直占用内存。回收机制一般不会删除Cache

默认时间是
absoluteExpiration 参数设置为等于 MaxValue,后者是表示最大可能的 DateTime 值 12/31/9999 11:59:59 PM 的常数。
fellowcheng 2010-11-17
  • 打赏
  • 举报
回复
好像是会话有效
YSEE 2010-11-17
  • 打赏
  • 举报
回复
我就是想知道下 不设置的 后果。
C#的回收机制 是否会清理 还是什么~?
无心雨云 2010-11-17
  • 打赏
  • 举报
回复
默认的不知道
不过你可以设置啊
孟子E章 2010-11-17
  • 打赏
  • 举报
回复
默认是没有到期时间,应该是内存不足或者重启程序才会到期删除

111,120

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧