日期:2014-05-17 浏览次数:20496 次
using System;
using System.Collections.Generic;
using System.Web;
using System.Configuration;
using System.Collections;
/// <summary>
///CacheHelper 的摘要说明
/// </summary>
public class CacheHelper
{
#region 从配置文件中读取缓存时间
//缓存时间
private static string _CacheTime = string.Empty;
public static string CacheTime
{
get
{
try
{
_CacheTime = ConfigurationManager.AppSettings["CacheTime"].ToString();
}
catch (Exception)
{
_CacheTime = "0";
}
return _CacheTime;
}
set { _CacheTime = value; }
}
#endregion
public CacheHelper()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
#region 插入Cache
/// <summary>
/// 插入Cache
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="o"></param>
/// <param name="key"></param>
public static void Add<T>(T o, string key)
{
HttpContext.Current.Cache.Insert(
key,
o,
null,
DateTime.Now.AddMinutes(Convert.ToDouble(CacheTime)), // Cache的缓存时间,通常建议配置在Config文件中
System.Web.Caching.Cache.NoSlidingExpiration);
}
#endregion
#region 删除指定的Cache
/// <summary>
/// 删除指定的Cache
/// &