c# CacheManager 缓存管理
2024-08-30 11:19:56
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Collections; namespace Common
{
public static class CacheManager
{ /// <summary>
/// 获取数据缓存
/// </summary>
/// <param name="CacheKey">键</param>
public static object GetCache(string CacheKey)
{
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
return objCache[CacheKey];
} /// <summary>
/// 设置数据缓存
/// </summary>
public static void SetCache(string CacheKey, object objObject)
{
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
objCache.Insert(CacheKey, objObject);
} /// <summary>
/// 设置数据缓存
/// CacheKey
/// objObject
/// expires 分钟
/// </summary>
public static void SetCache(string CacheKey, object objObject, int expires)
{
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
objCache.Insert(CacheKey, objObject, null, DateTime.MaxValue, new TimeSpan(, expires, ), System.Web.Caching.CacheItemPriority.NotRemovable, null);
} /// <summary>
/// 设置数据缓存
/// </summary>
public static void SetCache(string CacheKey, object objObject, DateTime absoluteExpiration, TimeSpan slidingExpiration)
{
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
objCache.Insert(CacheKey, objObject, null, absoluteExpiration, slidingExpiration);
} /// <summary>
/// 移除指定数据缓存
/// </summary>
public static void RemoveCache(string CacheKey)
{
System.Web.Caching.Cache _cache = HttpRuntime.Cache;
_cache.Remove(CacheKey);
} /// <summary>
/// 移除全部缓存
/// </summary>
public static void RemoveAllCache()
{
System.Web.Caching.Cache _cache = HttpRuntime.Cache;
IDictionaryEnumerator CacheEnum = _cache.GetEnumerator();
while (CacheEnum.MoveNext())
{
_cache.Remove(CacheEnum.Key.ToString());
}
}
}
}
最新文章
- Vertical Menu ver4
- iOS 自定义方法 - UIView扩展
- 【codevs】刷题记录→_→(推荐看!)
- Oracle层次查询
- Android基于mAppWidget实现手绘地图(一)--简介
- [BZOJ1177][Apio2009]Oil
- SPI的工作模式口诀[转]
- Android学习笔记(2)
- ajaxFileUpload - Post file and data together
- Python for 循环 失效
- ThinkPHP实现RBAC
- group_concat()函数总结
- js筛选
- python_特殊函数
- 分布式系列六: WebService简介
- Codeforces Round #502 (in memory of Leopoldo Taravilse, Div. 1 + Div. 2)
- BootStrap学习(3)_导航菜单
- Windows10系统重置网络设置
- RPG游戏中如何判断敌人是否在玩家的攻击范围之内
- go中的无限极分类的问题
热门文章
- HDU——1061Rightmost Digit(高次方,找规律)
- [SCOI2008]配对 (贪心,动态规划)
- [POI2007]MEG-Megalopolis (树状数组,Dfs序)
- [暑假集训--数位dp]hdu3709 Balanced Number
- IOs动画的那些事儿
- codeforces 900D 数论+组合+容斥原理
- Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
- Linux 之 CentOS练习
- c#学习笔记之Application.DoEvents应用
- (1)sqlite基础