基本类-SystemCache

简单的通过.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;
        }
    }

  

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。