把Cache检回来
希望在Cache里面放一个对象,结果总是自动释放,如下:
2006-11-22 16:32:12 key=User_10,reason=Underused
无奈只好监视其如果丢掉的话自动找回来,不过痛苦的事是,累计40个左右underused以后再也没办法捡回来了。怎么办呢,看起来只能用Application了
2006-11-22 16:32:12 key=User_10,reason=Underused
无奈只好监视其如果丢掉的话自动找回来,不过痛苦的事是,累计40个左右underused以后再也没办法捡回来了。怎么办呢,看起来只能用Application了
/// <summary>
/// 把用户放入内存
/// </summary>
/// <param name="user"></param>
private void CacheUser(ISysUser user)
{
string cacheIdentifier = USER_CACHE_PREFIX + user.SysUser_Id.ToString();
HttpRuntime.Cache.Add(cacheIdentifier, user, null, DateTime.MaxValue, TimeSpan.FromMinutes(AUTHENTICATION_TIMEOUT), CacheItemPriority.Default, OnCacheRemoveCallBack);
}
///捡回来
private void OnCacheRemoveCallBack(string key, object value, CacheItemRemovedReason reason)
{
Platform.LogCoreException("key=" + key + ",reason=" + reason);
if(reason == CacheItemRemovedReason.Underused && value is ISysUser)
{
CacheUser((ISysUser) value);
}
}
/// 把用户放入内存
/// </summary>
/// <param name="user"></param>
private void CacheUser(ISysUser user)
{
string cacheIdentifier = USER_CACHE_PREFIX + user.SysUser_Id.ToString();
HttpRuntime.Cache.Add(cacheIdentifier, user, null, DateTime.MaxValue, TimeSpan.FromMinutes(AUTHENTICATION_TIMEOUT), CacheItemPriority.Default, OnCacheRemoveCallBack);
}
///捡回来
private void OnCacheRemoveCallBack(string key, object value, CacheItemRemovedReason reason)
{
Platform.LogCoreException("key=" + key + ",reason=" + reason);
if(reason == CacheItemRemovedReason.Underused && value is ISysUser)
{
CacheUser((ISysUser) value);
}
}