c#自带缓存使用方法 c#移除清理缓存
时间:2021-09-07 10:20:15
/// <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>
/// 设置数据缓存
/// </summary>
public static void SetCache(string CacheKey, object objObject, TimeSpan Timeout)
{
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
objCache.Insert(CacheKey, objObject, null, DateTime.MaxValue, Timeout, 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 RemoveAllCache(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());
}
}
标签:c#,缓存
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
一文探索Java文件读写更高效方式
2021-12-20 08:31:22
Android 实现永久保存数据的方法详解
2023-06-23 22:13:23
聊聊@RequestBody和Json之间的关系
2023-11-27 03:31:45
java中的实体类时间格式化
2022-05-18 02:18:19
![](https://img.aspxhome.com/file/2023/3/63393_0s.png)
Mybatis表的关联查询详情
2023-11-23 12:15:03
![](https://img.aspxhome.com/file/2023/3/85893_0s.png)
iOS获取AppIcon and LaunchImage's name(app图标和启动图片名字)
2022-01-11 02:39:14
![](https://img.aspxhome.com/file/2023/7/78917_0s.png)
springmvc和js前端的数据传递和接收方式(两种)
2021-06-15 08:33:37
SpringMVC 域对象共享数据的实现示例
2021-07-18 15:45:57
![](https://img.aspxhome.com/file/2023/6/75016_0s.png)
深入了解C#设计模式之订阅发布模式
2021-08-14 05:31:39
Spring security如何重写Filter实现json登录
2023-09-15 13:33:31
SpringBoot+WebSocket实现即时通讯的方法详解
2021-07-24 15:48:49
![](https://img.aspxhome.com/file/2023/6/78866_0s.png)
C#多线程系列之线程的创建和生命周期
2023-08-31 17:10:16
![](https://img.aspxhome.com/file/2023/2/77262_0s.jpg)
Java接口的作用_动力节点Java学院整理
2021-12-23 20:46:14
![](https://img.aspxhome.com/file/2023/0/61570_0s.png)
浅析Java中的异常处理机制
2021-08-19 05:42:48
mybatis QueryWrapper的条件构造之apply、last、select解析
2022-02-12 17:32:51
java实现的RSA加密算法详解
2022-11-19 06:14:44
Java实现微信红包分配规则
2021-06-16 09:18:07
![](https://img.aspxhome.com/file/2023/8/66168_0s.png)
SpringBoot过滤器与拦截 器深入分析实现方法
2023-11-28 23:04:15
Java中Lambda表达式和函数式接口的使用和特性
2023-06-20 20:05:42
Java集合系列之ArrayList源码分析
2023-01-31 03:02:36