码迷,mamicode.com
首页 > 系统相关 > 详细

基本类-SystemCache

时间:2014-11-05 12:14:50      阅读:284      评论:0      收藏:0      [点我收藏+]

标签:blog   http   io   ar   os   sp   div   on   log   

简单的通过.net K-V形式操作Cache:

public enum CacheKey
    {
        LanguageQueryProcess_FetchAll,
        ProjectQueryProcess_FetchAll
    }

    public class SystemCache
    {
        /// <summary>
        /// HttpContext.Current.Cache.Insert(string key, object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration)
        /// Set cache
        /// 
        /// default 20 minutes
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        public static void SetCache(CacheKey key, object value, int expirationMinutes = 20)
        {
            DateTime expirationTime = DateTime.Now.AddMinutes(expirationMinutes);
            HttpContext.Current.Cache.Insert(
                key.ToString()
                , value
                , null
                , expirationTime
                , TimeSpan.Zero
                );
        }

        /// <summary>
        /// get cache
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static object GetCache(CacheKey key)
        {
            object value = HttpContext.Current.Cache.Get(key.ToString());
            return value;
        }
    }

  

基本类-SystemCache

标签:blog   http   io   ar   os   sp   div   on   log   

原文地址:http://www.cnblogs.com/xiguain/p/4075691.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!