点击下载 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());
}
}
}
}

[Cache] C#操作缓存--CacheHelper缓存帮助类 (转载)的更多相关文章

  1. [Cache] C#操作缓存--CacheHelper缓存帮助类 [复制链接]

    using System;using System.Web;using System.Collections; namespace DotNet.Utilities{ public class Cac ...

  2. C#操作缓存--CacheHelper缓存帮助类

    /// <summary>/// 类说明:Assistant/// 联系方式:361983679  /// 更新网站:<a href=\"http://www.cckan. ...

  3. System.Web.Caching.Cache类 缓存 各种缓存依赖

    原文:System.Web.Caching.Cache类 缓存 各种缓存依赖 Cache类,是一个用于缓存常用信息的类.HttpRuntime.Cache以及HttpContext.Current.C ...

  4. System.Web.Caching.Cache类 缓存 各种缓存依赖(转)

    转自:http://www.cnblogs.com/kissdodog/archive/2013/05/07/3064895.html Cache类,是一个用于缓存常用信息的类.HttpRuntime ...

  5. System.Web.Caching.Cache类 Asp.Net缓存 各种缓存依赖

    Cache类,是一个用于缓存常用信息的类.HttpRuntime.Cache以及HttpContext.Current.Cache都是该类的实例. 一.属性 属性 说明 Count 获取存储在缓存中的 ...

  6. C# System.Web.Caching.Cache类 缓存 各种缓存依赖

    原文:https://www.cnblogs.com/kissdodog/archive/2013/05/07/3064895.html Cache类,是一个用于缓存常用信息的类.HttpRuntim ...

  7. 初学C#和MVC的一些心得,弯路,总结,还有教训(4)--Cache 关于创建多个缓存实例

    asp.net中的数据缓存可以用 HttpRuntime.Cache ,这个是大家都知道的,但如果缓存的数据比较多,又比较杂乱,想要把缓存分开管理(也就是创建多个缓存实例)应该怎么做呢... 于是常规 ...

  8. ASP.NET Cache 实现依赖Oracle的缓存策略

    ASP.NET 中的缓存提供了对SQL依赖项的支持,也就是说当SQL SERVER数据库中的表或行中的数据被更改后,缓存中的页面就失效,否则,页面输出可一直保留在缓存当中.这确实为程序员提供了方便.但 ...

  9. 带缓存的输入输出-bufferedinputstream类与bufferedoutputstream类

    package hengzhe.cn.o1; import java.io.*; /* * 带缓存的输入输出-bufferedinputstream类与bufferedoutputstream类 * ...

随机推荐

  1. 在服务 ObtainData 实现的协定列表中找不到协定名称 "IMetadataExchange"。将 ServiceMetadataBehavior 添加到配置文件或直接添加到 ServiceHost,以启用对该协定的支持。

    第一种解决方法:最暴力的 配置去掉<endpoint address="mex" binding="mexHttpBinding" contract=&q ...

  2. hadoop2.2编程: 重写comparactor

    要点: 类型比较在hadoop的mapreduce中非常重要,主要用来比较keys; hadoop中的RawComparator<T>接口继承自java的comparator, 主要用来比 ...

  3. POJ_3666_Making_the_Grade_(动态规划)

    描述 http://poj.org/problem?id=3666 给一串坡的高度,现在要调整某些点,使整个坡单调不降或单调不升.调整的花费为原高度与先高度的差的绝对值,问最小花费(可单增可单降). ...

  4. fsl的feat软件分包使用笔记

    introduction: 1. feat 是一种基于模型的fmri数据分析方法. 2. feat 首先使用顺手,至少看起来,比spm漂亮多了. feat是按照正常人的使用方法去设计的. spm 由于 ...

  5. 解决Windows8系统磁盘占用太多100%或99%

    关闭家庭组功能:WIN+R运行Services.msc,找到 HomeGroup Listener 和 HomeGroup Provider 服务,分别停止和禁用这2个服务.然后重新启动Windows ...

  6. Linux下Java环境变量设置

    我用的是oh my zsh,需要修改.zshrc,记一下免得以后忘记在哪儿改的. 如果你用的是自带的terminal那么用文本编辑器打开用户目录下的.bash_profile文件 在.bash_pro ...

  7. SRM 442(1-250pt, 1-500pt)

    DIV1 250pt 题意:将一个数表示成质因子相乘的形式,若乘式所含数字的个数为质数,则称A为underprime.比如12 = 2*2*3,则含3个数字,是underprime.求A, B之间un ...

  8. HDU 4722 Good Numbers

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4722 Good Numbers Time Limit: 2000/1000 MS (Java/Othe ...

  9. hdoj 2767 Proving Equivalences【求scc&&缩点】【求最少添加多少条边使这个图成为一个scc】

    Proving Equivalences Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  10. 获取toast值

    /** * 获取Toast的String值 * @return */ public String getToast(int timeout){ TextView toastTextView = nul ...