过去几个小时我一直在为这个问题烦恼。
我有一个缓存对象..
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/