您可以在第四个参数Cache.Add()
中指定它:
public Object Add(
string key,
Object value,
CacheDependency dependencies,
DateTime absoluteExpiration, // After this DateTime, it will be removed from the cache
TimeSpan slidingExpiration,
CacheItemPriority priority,
CacheItemRemovedCallback onRemoveCallback
)
如果您通过索引器(即Cache["Key"]
)访问缓存,则被调用的方法将不使用过期,并无限期地保留在缓存中.
以下是使用索引器时调用的代码:
public void Insert(string key, object value)
{
this._cacheInternal.DoInsert(true, key, value, null, NoAbsoluteExpiration, NoSlidingExpiration, CacheItemPriority.Normal, null, true);
}