加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – HttpContext.Cache到期

发布时间:2020-12-15 19:12:38 所属栏目:asp.Net 来源:网络整理
导读:有没有办法指定在HttpContext.Cache中保存数据的时间? 解决方法 您可以在Cache.Add()的第4个参数中指定它: public Object Add( string key,Object value,CacheDependency dependencies,DateTime absoluteExpiration,// After this DateTime,it will be rem
有没有办法指定在HttpContext.Cache中保存数据的时间?

解决方法

您可以在Cache.Add()的第4个参数中指定它:
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,true);
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读