C# 缓存操作类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Caching; namespace Utility
{
/// <summary>
/// 缓存操作,默认缓存1分钟
/// </summary>
public static class CacheHelper
{
static int cacheTime = 1; /// <summary>
/// 读取缓存项
/// </summary>
/// <returns></returns>
public static object CacheReader(string cacheKey)
{
return HttpRuntime.Cache[cacheKey];
} /// <summary>
/// 写入缓存项
/// </summary>
public static void CacheWriter(string cacheKey, object cacheValue, int cache_time = 0)
{
HttpRuntime.Cache.Insert(cacheKey, cacheValue, null,
DateTime.Now.AddMinutes(cache_time <= 0 ? cacheTime : cache_time),
Cache.NoSlidingExpiration);
} /// <summary>
/// 移除指定缓存项
/// </summary>
public static void CacheRemove(string cacheName)
{
HttpRuntime.Cache.Remove(cacheName);
} /// <summary>
/// 缓存对象泛型实现
/// </summary>
public static T ObjectReader<T>(string cacheKey = null)
where T : class
{
string cachekey = typeof(T).GetHashCode() + StringHelper.ToString(cacheKey);
var obj = CacheReader(cachekey) as T;
return obj;
} /// <summary>
/// 缓存对象泛型实现
/// </summary>
public static void ObjectWriter<T>(T cacheValue, string cacheKey = null, int cache_time = 0)
where T : class
{
string cachekey = typeof (T).GetHashCode() + StringHelper.ToString(cacheKey);
CacheWriter(cachekey, cacheValue, cache_time);
}
}
}
C# 缓存操作类的更多相关文章
- 封装php redis缓存操作类
封装php redis缓存操作类,集成了连接redis并判断连接是否成功,redis数据库选择,检测redis键是否存在,获取值,写入值,设置生存时间和删除清空操作. php redis类代码: &l ...
- 3.NetDh框架之缓存操作类和二次开发模式简单设计(附源码和示例代码)
前言 NetDh框架适用于C/S.B/S的服务端框架,可用于项目开发和学习.目前包含以下四个模块 1.数据库操作层封装Dapper,支持多种数据库类型.多库实例,简单强大: 此部分具体说明可参考博客: ...
- C#语法糖之 cache操作类 asp.net
因为考虑到我下面我将写session cookies 等 操作类 ,与cache具有共性. 所以都统一继承了IHttpStorageObject abstract class 来保函数风格的统一 , ...
- Cache操作类
封装类: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Sys ...
- [Cache] C#操作缓存--CacheHelper缓存帮助类 (转载)
点击下载 CacheHelper.zip CacheHelper 缓存帮助类 C#怎么操作缓存 怎么设置和取缓存数据,都在这个类里面呢 下面看一下代码吧 /// <summary> /// ...
- PHP 数据库操作类:ezSQL
EZSQL类介绍: 下载地址:http://www.jb51.net/codes/26393.htmlezsql是一个小型的快速的数据库操作类,可以让你很容易地用PHP操作各种数据库( MySQL.o ...
- 【代码笔记】iOS-缓存路径操作类
一,代码. AppDelegate.h #import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplica ...
- thrift之TTransport层的缓存传输类TBufferedTransport和缓冲基类TBufferBase
本节主要介绍缓冲相关的传输类,缓存的作用就是为了提高读写的效率.Thrift在实现缓存传输的时候首先建立一个缓存的基类,然后需要实现缓存功能的类都可以直接从这个基类继承.下面就详细分析这个基类以及一个 ...
- C#语法糖之Cookies操作类 asp.net
用法: //声名一个数据集合 var listString = new List<string>() { "a", "b", "c&quo ...
随机推荐
- Linux基础命令---切换用户su
su 临时切换身份到另外一个用户,使用su切换用户之后,不会改变当前的工作目录,但是会改变一些环境变量. 此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.SUSE.openSUS ...
- C#获取驱动器盘符
一.使用ManagementObjectSearcher类 static void Main(string[] args) { SelectQuery selectQuery = new Select ...
- rabbitMq 教程
https://github.com/401Studio/WeekLearn/issues/2 目录 RabbitMQ 概念 exchange交换机机制 什么是交换机 binding? Direct ...
- 【JavaScript 6连载】四、apply和call的用法
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- linux下postgresql的连接数配置
1.查询当前连接数: select count(*) from pg_stat_activity; 2.查询最大连接数 show max_connections; 3.修改最大连接数 SHOW con ...
- vue editorConfig
在文件目录下, indent_size = 2设置为4
- redis 的数据结构
Redis 数据类型 详解见: http://www.runoob.com/redis/redis-strings.html Redis支持五种数据类型:string(字符串),hash(哈希),li ...
- Spring数据库开发
Spring的数据库开发 #Spring中JDBC模板的作用 JDBC模板负责数据库资源管理和错误处理: #熟悉Spring JDBC的配置 配置数据源和jdbc模板 <?xml versio ...
- 关于HashSet的equals和hashcode的重写
关于HashSet的equals和hashcode的重写:package Test; import java.util.HashSet; import java.util.Set; public cl ...
- php 网站中文简体繁体转换类
php 网站中文简体繁体转换类 <?php /* * define zh convert functions * 2017-4-28 use str_replace for speed * zh ...