YFCache

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/*HttpRuntime.Cache.Add( 
       KeyName,//缓存名 
       KeyValue,//要缓存的对象 
       Dependencies,//依赖项 
       AbsoluteExpiration,//绝对过期时间 
       SlidingExpiration,//相对过期时间 
       Priority,//优先级 
       CacheItemRemovedCallback);//缓存过期引发事件*/

namespace YFAPICommon.Libs
{
    public class YFCache
    {
        /// <summary>  
        /// 获取数据缓存  
        /// </summary>    
        /// <param name="CacheKey">键</param>  
        public static object GetCache(string CacheKey)
        {
            return HttpRuntime.Cache[CacheKey];
        }

        /// <summary>    
        /// 设置数据缓存    
        /// </summary>    
        public static void SetCache(string CacheKey, object objObject)
        {
            HttpRuntime.Cache.Insert(CacheKey, objObject);
        }

        /// <summary>    
        /// 设置数据缓存  
        /// </summary>    
        public static void SetCache(string CacheKey, object objObject, TimeSpan Timeout)
        {
            HttpRuntime.Cache.Insert(CacheKey, objObject, null, DateTime.MaxValue, Timeout);
        }

        /// <summary>    
        // 设置数据缓存    
        /// </summary>    
        public static void SetCache(string CacheKey, object objObject, DateTime absoluteExpiration)
        {
            HttpRuntime.Cache.Insert(CacheKey, objObject, null, absoluteExpiration, TimeSpan.Zero);
        }

        /// <summary>    
        // 设置数据缓存    
        /// </summary>    
        public static void SetCache(string CacheKey, object objObject, DateTime absoluteExpiration, TimeSpan slidingExpiration)
        {
            HttpRuntime.Cache.Insert(CacheKey, objObject, null, absoluteExpiration, slidingExpiration);
        }

        /// <summary>    
        /// 移除指定数据缓存    
        /// /// </summary>   
        public static void RemoveCache(string CacheKey)
        {
            HttpRuntime.Cache.Remove(CacheKey);
        }

        /// <summary>   
        /// 移除全部缓存    
        /// </summary>    
        public static void RemoveAllCache()
        {
            IDictionaryEnumerator CacheEnum = HttpRuntime.Cache.GetEnumerator();
            while (CacheEnum.MoveNext())
            {
                HttpRuntime.Cache.Remove(CacheEnum.Key.ToString());
            }
        }
    }
}

HttpRuntime.Cache的用法参看:https://zzzili.blog.csdn.net/article/details/109842514

 

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页