C# 缓存操作类
            
            
                    
                        标签:run   text   move   pru   log   hash   object c   col   object   
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Caching;
 
namespace Utility
{
    /// 
    /// 缓存操作,默认缓存1分钟
    /// 
    public static class CacheHelper
    {
        static int cacheTime = 1;
 
        /// 
        /// 读取缓存项
        /// 
        /// 
        public static object CacheReader(string cacheKey)
        {
            return HttpRuntime.Cache[cacheKey];
        }
 
        /// 
        /// 写入缓存项
        /// 
        public static void CacheWriter(string cacheKey, object cacheValue, int cache_time = 0)
        {
            HttpRuntime.Cache.Insert(cacheKey, cacheValue, null,
                DateTime.Now.AddMinutes(cache_time 
        /// 移除指定缓存项
        /// 
        public static void CacheRemove(string cacheName)
        {
            HttpRuntime.Cache.Remove(cacheName);
        }
 
        /// 
        /// 缓存对象泛型实现
        /// 
        public static T ObjectReader(string cacheKey = null)
            where T : class
        {
            string cachekey = typeof(T).GetHashCode() + StringHelper.ToString(cacheKey);
            var obj = CacheReader(cachekey) as T;
            return obj;
        }
 
        /// 
        /// 缓存对象泛型实现
        /// 
        public static void ObjectWriter(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# 缓存操作类
标签:run   text   move   pru   log   hash   object c   col   object   
原文地址:http://www.cnblogs.com/XuPengLB/p/7644619.html
                    
             
            
            
            
            
                
                    文章来自:
搜素材网的
编程语言模块,转载请注明文章出处。
                    文章标题:
C# 缓存操作类
                    文章链接:http://soscw.com/index.php/essay/83617.html                
 
            
                                
评论