在本机上面测试
webCache.Insert(key, o, null, DateTime.Now.AddMinutes(60), System.Web.Caching.Cache.NoSlidingExpiration,CacheItemPriority.High, callback);60分钟 cache 才消失为什么放服务器上 1分中不到就消失了
webCache.Insert(key, o, null, DateTime.Now.AddMinutes(60), System.Web.Caching.Cache.NoSlidingExpiration,CacheItemPriority.High, callback);60分钟 cache 才消失为什么放服务器上 1分中不到就消失了
你可以把重要的cache的权值设高一点,这样会往后拖一点.如果是固定的数据,需要频繁使用的数据,可以直接放到application中,或者弄成应用程序全局静态成员.这样,在应用池重启之前,它们是永远有效的.
public static object GetCache(string CacheKey)
{
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
return objCache[CacheKey];
}
public static void SetCache(string CacheKey, object objObject, System.Web.Caching.CacheDependency dep)
{
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
objCache.Insert(CacheKey,objObject, dep,System.Web.Caching.Cache.NoAbsoluteExpiration,//从不过期
System.Web.Caching.Cache.NoSlidingExpiration,//禁用可调过期
System.Web.Caching.CacheItemPriority.Default,null);
}