C#自带缓存方案
2024-10-21 09:22:00
/// <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());
}
}
最新文章
- MVC 下 JsonResult 的使用方法(JsonRequestBehavior.AllowGet)【转】
- 自定义Java集合
- Android属性之build.prop生成过程分析
- jquery 展开折叠效果
- Linux之samba搭建
- RichTextBox 自动滚动到最后
- UVa 12304 (6个二维几何问题合集) 2D Geometry 110 in 1!
- 解决eclipse复制粘贴js代码卡死的问题
- Hubot Slack CoffeeScript
- NSRunLoop个人理解
- Objective-C 链式编程思想
- Redis6-sorted set 的介绍
- UVALive 2517	Moving Object Recognition(模拟)
- Base-64编码介绍
- null和undefined的异同
- css选择器概述
- Saving custom fields in production order
- [CF1038D]Slime
- FJUT3701 这也是一道数论题(线段树)题解
- 超轻量级Json框架SmartObject
热门文章
- git clone,push,pull,fetch命令详解
- 使用Git【转】
- Signing package index... Cannot open file &#39;/home/jello/openwrt/key-build&#39; for reading
- codeforces 300 div2 B.Pasha and Phone 容斥原理
- 个人知识管理系统Version1.0开发记录(05)
- IOS-网络(文件压缩和解压缩)
- google搜索 site:pku.edu.cn inurl:aspx 即可查找所有动态网页 =====html(静态网页) asp(动态) jsp(动态) php(动态) cgi(网络程序) aspx(动态)
- word问题禁止宏
- easyui panel自适应浏览器宽度
- PHP7.2.12-Configuration-Option