如何防止ASP.NET从缓存中删除项目 [英] How to prevent ASP.NET from removing items from cache
问题描述
我想将一个项目永久添加到缓存中。我正在使用以下语法:
I want to permanently add an item to the cache. I am using the following syntax:
HttpContext.Current.Cache.Insert(cacheName, c, null, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration);
我发现,ASP.NET有时仍会从缓存中删除项目。
I have found out, that ASP.NET still sometimes removes items from the cache.
关于如何防止这种情况的任何想法(除了删除缓存并使用存储在静态成员中的Dictionary之外?
Any ideas on how to prevent this (in addition to dropping the cache and using Dictionary stored in a static member?
Matra
推荐答案
我的答案不正确,请请参见此处以获取正确答案。
My answer is not correct. Please see here for a correct answer.
您不能阻止ASP.NET删除项目
You can't prevent ASP.NET from removing items from the cache (e.g. when memory gets low).
如果需要在应用程序的整个生命周期中存储数据,则将其放入ApplicationState集合中,例如:
If you need to store data for the whole lifetime of the application, then put it into the ApplicationState collection, e.g:
Application["myData"] = ...;
这类似于SessionState集合,但顾名思义,它是整个应用程序的。
This is similar to the SessionState collection, but as the name says, it's application-wide.
这篇关于如何防止ASP.NET从缓存中删除项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!