Cache介绍:
出生于.NetFramework 2,实现用于 Web 应用程序的缓存。
代码
简单的封装,有更好的封装代码,欢迎指点。
''''
/// <summary>
/// 缓存操作类
/// </summary>
public class DataCache
{
/// <summary>
/// 获取当前应用程序指定CacheKey的Cache值
/// </summary>
/// <param name="CacheKey"></param>
/// <returns></returns>
public static object GetCache(string CacheKey)
{
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
return objCache[CacheKey];
}
/// <summary>
/// 设置当前应用程序指定CacheKey的Cache值
/// </summary>
/// <param name="CacheKey"></param>
/// <param name="objObject"></param>
/// <param name="Seconds">超过多少秒后过期</param>
public static void SetCache(string CacheKey, object objObject, long Seconds)
{
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
objCache.Insert(CacheKey, objObject, null, System.DateTime.Now.AddSeconds(Seconds), TimeSpan.Zero);
}
/// <summary>
/// 移除指定key的数据缓存
/// </summary>
/// <param name="CacheKey">cache 的key值</param>
public static void RemoveCache(string CacheKey)
{
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
objCache.Remove(CacheKey);
}
}
'''
|