c# - 绝对过期缓存对象 - 可以手动删除吗?

标签 c# caching

过去几个小时我一直在为这个问题烦恼。

我有一个缓存对象..

HttpRuntime.Cache.Insert("Members", AllMembersList, null, DateTime.Now.AddHours(1), TimeSpan.Zero);

当我尝试清除缓存对象时..

HttpRuntime.Cache.Remove("Members");

它的值不会改变,直到 1 小时结束或当我重置服务器时。

我的问题..对于设置绝对过期的缓存对象,我可以手动清除它还是它会存在一整小时?

我希望这个对象持续一个小时,但根据程序执行能够清除它,以便它将包含新数据。

非常感谢任何帮助

真吉利

最佳答案

来自http://www.neovolve.com/page/Cache-Expiration-Policies.aspx

When are items actually flushed from the cache?

Most caching frameworks will only remove expired items from the cache when system resources are scarce or when the cache is referenced. This means that a cache entry that has expired due to an absolute or sliding expiration may not be removed from the cache until some future time which may be well after the entry actually expired.

This is done for performance. The caching frameworks normally use a scavenging algorithm that looks for expired entries and removes them. This is typically invoked when the cache is referenced rather than when the items actually expire. This allows the cache framework to avoid having to constantly track time based events to know when to remove items from the cache.

您可以尝试将缓存值设置为 null。

关于c# - 绝对过期缓存对象 - 可以手动删除吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2692727/

相关文章:

c# - 有没有办法在 C# 中 Hook 托管函数,就像在 C++ 中 Hook 非托管函数一样?

c# - PDFCreator COM 与不同版本的互操作

C# 窗体 : Accessing Outlook with Multiple Mailboxes

asp.net-mvc-3 - 如何关闭整个ASP.NET MVC 3网站的缓存?

html - list 更新时无法获取 iOS webapp 文件。 401未经授权

multithreading - MOESI 缓存一致性协议(protocol)相对于 MESI 有什么好处?

c# - 基本类型还是复杂类型?

c# - 如何将数据从 View 传递到 View 模型

ios - NSURLCache 线程安全吗?

.htaccess - 启用缓存 Google PageSpeed