博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
c# CacheManager 缓存管理
阅读量:7183 次
发布时间:2019-06-29

本文共 2090 字,大约阅读时间需要 6 分钟。

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    {        ///           /// 获取数据缓存          ///           /// 键          public static object GetCache(string CacheKey)        {            System.Web.Caching.Cache objCache = HttpRuntime.Cache;            return objCache[CacheKey];        }        ///           /// 设置数据缓存          ///           public static void SetCache(string CacheKey, object objObject)        {            System.Web.Caching.Cache objCache = HttpRuntime.Cache;            objCache.Insert(CacheKey, objObject);        }        ///           /// 设置数据缓存        /// CacheKey          /// objObject         ///  expires  分钟        ///           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(0, expires, 0), System.Web.Caching.CacheItemPriority.NotRemovable, null);        }        ///           /// 设置数据缓存          ///           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);        }        ///           /// 移除指定数据缓存          ///           public static void RemoveCache(string CacheKey)        {            System.Web.Caching.Cache _cache = HttpRuntime.Cache;            _cache.Remove(CacheKey);        }        ///           /// 移除全部缓存          ///           public static void RemoveAllCache()        {            System.Web.Caching.Cache _cache = HttpRuntime.Cache;            IDictionaryEnumerator CacheEnum = _cache.GetEnumerator();            while (CacheEnum.MoveNext())            {                _cache.Remove(CacheEnum.Key.ToString());            }        }      }}

 

转载地址:http://llukm.baihongyu.com/

你可能感兴趣的文章
&.nbsp;在IE和谷歌浏览器中不兼容的解决办法
查看>>
Servlet容器
查看>>
捷为科技签约镇海石化, 打造石化建安行业生产项目信息化管理系统
查看>>
我的友情链接
查看>>
我的友情链接
查看>>
Java异常
查看>>
Java开发中的23种设计模式详解
查看>>
Spring Aop实例
查看>>
Vlan学习笔记终极整理
查看>>
设置文本框输入不同值
查看>>
数据结构之顺序表
查看>>
Linux高可用集群方案之heartbeat基础原理及逻辑架构
查看>>
Oracle同义词创建及作用,数据库链接Database Link
查看>>
Scrapy框架下第一个爬虫
查看>>
自动化运维工具puppet(五)
查看>>
linux网络命令(八)之top、htop
查看>>
【Windows和Linux下定时删除某天前的文件的脚本】
查看>>
长视频的危机:直播和短视频的爆发式增长
查看>>
医疗信息化 医学 医院管理 资料下载
查看>>
centos6.5搭建docker私有库
查看>>