如何编写asp.net代码,将对象集合添加到60分钟后过期的缓存中
本文关键字:60分钟 过期 缓存 添加 集合 net asp 何编写 代码 对象 | 更新日期: 2023-09-27 17:52:54
我想编写asp.net代码,添加名为colSatates的对象集合到缓存后60分钟到期?如何将列表添加到60分钟内到期的兑现中?
var expire = DateTime.Now.AddHours(1);
var colSatatesObj = { ... }; // your object here
HttpContext.Current.Cache.Insert("colSatates", colSatatesObj, null, expire, Cache.NoSlidingExpiration);
以上代码将colSatatesObj对象打包到应用程序缓存中1小时,之后通过"colSatates"键名检索时将返回null
。
检索:
var colSatatesObj = HttpContext.Current.Cache["colSatates"] as ColSatateClassName; // whatever your class is called.
if (colSatatesObj != null) {
// do stuff with colSatatesObj
}