Common/CacheManager.cs
(开头部分) 3KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.Caching;
namespace Common
{
/// <summary>
/// 缓存处理类
/// </summary>
public class CacheManager
{
private static object lockObj = new object();
/// <summary>
/// 缓存对象
/// </summary>
private static System.Web.Caching.Cache webcache = System.Web.HttpRuntime.Cache;
/// <summary>
/// 默认缓存时间(1小时)
/// </summary>
private static int _timeOut = 3600;
/// <summary>
/// 设置到期相对时间[单位: 秒]
/// </summary>
public static int TimeOut
{
set { _timeOut = value > 0 ? value : 3600; }
get { return _timeOut > 0 ? _timeOut : 3600; }
}
/// <summary>
/// 添加常用数据到缓存,使用滑动到期时间
/// </summary>
/// <param name="objId"></param>
/// <param name="value"></param>
public static void AddObjectOfenUsed(string objId, object value)
{
if (objId == null || objId.Length == 0 || value == null)
{
return;
}
lock (lockObj)
{
webcache.Insert(objId, value, null,
System.Web.Caching.Cache.NoAbsoluteExpiration,
TimeSpan.FromSeconds(TimeOut));//滑动到期时间
}
}
/// <summary>
/// 添加普通数据到缓存,使用绝对时间
/// </summary>
/// <param name="objId"></param>
/// <param name="value"></param>
public static void AddObjectNormal(string objId, object value)
{
if (objId == null || objId.Length == 0 || value == null)
{
后面还有 56 行代码,购买后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
