奇怪,泛型不能cache缓存吗??

lixiaolong1224 lixiaolong1224 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
//infoModel是实体类
List<infoModel> myList = null;

//读取各分类下面资讯
if (Cache["exhiCategroyInfo"] == null)
{
myList = new info().getInfoIndexTopInfo();
if (myList != null)
{
//缓存委托
CacheItemRemovedCallback callBack = new CacheItemRemovedCallback(onCategroyInfoRemove);

//缓存时间(秒)
new dbCache().insertCache("exhiCategroyInfo", myList, 3000, callBack);
}
}
else
{
myList = (List<infoModel>)Cache["exhiCategroyInfo"];
}

private void onCategroyInfoRemove(string key, object value, CacheItemRemovedReason reason)
{
//create an instance of the callback delegate
CacheItemRemovedCallback callBack =
new CacheItemRemovedCallback(onCategroyInfoRemove);
new dbCache().insertCache(key, value, 3000, callBack);
}
//insertCache
public void insertCache(string cacheKey, object cacheValue, int cacheTime, CacheItemRemovedCallback callBack)
{
//判断缓存是否存在
if (!checkCacheKeyIsExist(cacheKey))
{
Cache _cache = HttpRuntime.Cache;

_cache.Insert(cacheKey, cacheValue, null, System.DateTime.Now.AddSeconds((double)cacheTime), Cache.NoSlidingExpiration, CacheItemPriority.Default, callBack);
}
else
HttpContext.Current.Response.Write("抱歉,该名称的缓存已存在!");
}

//我调试了,确认数据已经被缓存;当我重新刷新页面,缓存竟然为空,为什么呢??
...全文
评论 11
收藏 已收藏
分享
返回顶部
lixiaolong1224
.NET社区 62,272 成员 668,968 内容