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);
}
}
}

  

最新文章

  1. Delphi Code Editor 之 编辑器选项
  2. jQuery $(document).ready()和JavaScript onload事件
  3. MongoDB 索引相关知识
  4. 如何解决cellIndex在IE下兼容性问题
  5. 漫谈刑事辩护 z
  6. .Net 4.0 Convert Object to XDocument
  7. python基础之 optparse.OptionParser
  8. cdn与http缓存
  9. PHP查询MYSQL表的主键
  10. 在WebBrowser控件使用js调用C#方法
  11. Django学习(4)表单,让数据库更美好
  12. 半小时入门Thrift
  13. linux普通帐号可以临时切换到root(添加用户到sudoers中)
  14. bootstrap datetimepicker
  15. jq 获取当前屏幕高度
  16. CCF认证201712-1最小差值
  17. java两年工作经验有什么经验
  18. MFC程序开始的执行过程详述
  19. 深入浅出Docker(三):Docker开源之路
  20. 在 LINQ to Entities 查询中无法构造实体或复杂类型&ldquo;Mvc_MusicShop_diy.Models.Order&rdquo;

热门文章

  1. 创建一个简单的WCF程序2——手动开启/关闭WCF服务与动态调用WCF地址
  2. 区块链区块的生成和链接,比特币btc的产生,UTXO的生成和消耗,比特币系统
  3. IPERF 网络性能测试
  4. web前端学习:JavaScript学习指南
  5. GoldenGate实时投递数据到大数据平台(3)- Apache Flume
  6. Kali linux apt-get update 失败,无release……(最有效)
  7. JOBDU 题目1131:合唱队形
  8. ELK学习笔记之F5-HTTP-requesting-logging logstash filter
  9. select2 AJAX获取数据
  10. ora-24550 signo=6 signo=11解决