Common/Cache/CacheManage.cs
(开头部分) 8KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.Caching;
namespace Common
{
//方法1:Cache["CacheName"] = "CacheValue";
//方法2:Cache.Insert("CacheName","CacheValue","缓存依赖","绝对过期时间","弹性过期时间","优先级","");
//方法3:Cache.Add("CacheName","CacheValue","缓存依赖","绝对过期时间","弹性过期时间","优先级","");
/// <summary>
///CacheManage 的摘要说明
/// </summary>
public class CacheManage
{
protected static volatile System.Web.Caching.Cache webCache = System.Web.HttpRuntime.Cache;
protected int _timeOut = 1440; // 默认缓存存活期为1440分钟(24小时)
public CacheManage()
{
CacheItemRemovedCallback callback = new CacheItemRemovedCallback(onRemove);
}
/// <summary>
/// 设置到期相对时间[单位:/分钟]
/// </summary>
public int TimeOut
{
set { _timeOut = value > 0 ? value : 6000; }
get { return _timeOut > 0 ? _timeOut : 6000; }
}
public static System.Web.Caching.Cache GetWebCacheObj
{
get { return webCache; }
}
/// <summary>
/// 加入当前对象到缓存中
/// </summary>
/// <param name="objId">对象的键值</param>
/// <param name="o">缓存的对象</param>
public void AddObject(string objId, object o)
{
if (objId == null || objId.Length == 0 || o == null)
{
return;
}
CacheItemRemovedCallback callBack = new CacheItemRemovedCallback(onRemove);
if (TimeOut == 6000)
{
webCache.Insert(objId, o, null, DateTime.MaxValue, TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, callBack);
}
后面还有 175 行代码,购买后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
