点击下载 CacheHelper.zip

CacheHelper 缓存帮助类 C#怎么操作缓存 怎么设置和取缓存数据,都在这个类里面呢

下面看一下代码吧

/// <summary>
/// 类说明:Assistant
/// 联系方式:361983679
/// 更新网站:[url=http://www.cckan.net/thread-655-1-1.html]http://www.cckan.net/thread-655-1-1.html[/url]
/// </summary>
using System;
using System.Web;
using System.Collections; namespace DotNet.Utilities
{
public class CacheHelper
{
/// <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());
}
}
}
}

最新文章

  1. Django中Form的Textarea字段
  2. 也谈Oracle异常: ORA-06502: PL/SQL: 数字或值错误 : 字符串缓冲区太小
  3. BarEditItem ContentTemplate
  4. ListView中多个EditText设置焦点 多次点击异常报错
  5. Java中Set集合的使用
  6. ListView优化相关
  7. 使用cwRsync实现windows下文件定时同步【转】
  8. Codeforces Round #359 (Div. 2) C. Robbers&#39; watch (暴力DFS)
  9. SSH 远程连接
  10. Vue.js快速入门
  11. ubuntu 12.04添加桌面启动器
  12. nodejs和npm的安装
  13. 带着萌新看springboot源码07
  14. 一文搞懂 Linux network namespace
  15. 【原创】Git 分支的合并【Learn Git Branching】
  16. Unicode 与 Unicode Transformation Format(UTF-8 / UTF-16 / UTF-32)
  17. Machine Learning 算法可视化实现1 - 线性回归
  18. Oracle 11.2.0.4 For Windows 64bit+32bit 数据库
  19. brotli压缩
  20. c# 从一个服务器 访问另外一个服务器上的文件

热门文章

  1. 转载--Linux命令top动态观察程序的变化
  2. Android线程计时器实现
  3. JavaScript高级程序设计47.pdf
  4. php 生成正态分布随机数
  5. 基于zabbix 内置key的应用
  6. Yii 通过composer 安装的方法
  7. struts2标签 遍历map集合
  8. Can&#39;t connect to MySQL server on localhost (10061)解决方法
  9. 创业公司求IOS、Android攻城狮一枚
  10. ios9中 UIStackView的使用