Cache缓存示例(WCF)
1、新增缓存
var cache = HttpRuntime.Cache; cache.Insert(缓存名称, 缓存数据, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 绝对过期时间(分钟), 0), CacheItemPriority.Default, CachedItemRemoveCallBack[回调函数]);
2、缓存回调函数(缓存到期后需要重新添加缓存)
/// <summary> /// 缓存到期后的回调函数 /// </summary> /// <param name="key">缓存名称</param> /// <param name="value">缓存的值</param> /// <param name="reason">缓存到期的原因</param> private void CachedItemRemoveCallBack(string key, object value, CacheItemRemovedReason reason) {}