WMPTCache/DefaultCacheStrategy.cs

(开头部分) 7KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Web;
using System.Collections;
using System.Web.Caching;

namespace WMPT.Cache
{
    public class DefaultCacheStrategy : ICacheStrategy
    {
        private static object lockHelper = new object();

        protected static volatile System.Web.Caching.Cache webCache = System.Web.HttpRuntime.Cache;

        /// <summary>
        /// 默认缓存存活期为3600秒(1小时)
        /// </summary>
        protected int _timeOut = 3600;

		private static object syncObj = new object();

		/// <summary>
		/// 构造函数
		/// </summary>
		static DefaultCacheStrategy()
		{   
            //lock (syncObj)
            //{
            //    //System.Web.HttpContext context = System.Web.HttpContext.Current;
            //    //if(context != null)
            //    //    webCache = context.Cache;
            //    //else
            //    webCache = System.Web.HttpRuntime.Cache;
            //}	
 		}
		
		/// <summary>
        /// 设置到期相对时间[单位: 秒] 
		/// </summary>
        public virtual int TimeOut
		{
            set { _timeOut = value > 0 ? value : 3600; }
            get { return _timeOut > 0 ? _timeOut : 3600; }
		}


        public static System.Web.Caching.Cache GetWebCacheObj
		{
			get { return webCache; }
		}
		
		/// <summary>
		/// 加入当前对象到缓存中
		/// </summary>
		/// <param name="objId">对象的键值</param>
		/// <param name="o">缓存的对象</param>
		public virtual void AddObject(string objId, object o)
		{	
			if (objId == null || objId.Length == 0 || o == null)
            {
                return;
后面还有 154 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。