zoukankan      html  css  js  c++  java
  • 缓存类

     /// <summary>
        /// CachePriceParamSetting类
        /// </summary>
        public class CachePriceParamSetting
        {
            /// <summary>
            /// 缓存参数集合
            /// </summary>
            private static List<MPriceParamSetting> priceParamSettingList = new List<MPriceParamSetting>();

            /// <summary>
            /// 缓存刷新时间
            /// </summary>
            private static int cacheIntervalTime = 5;

            /// <summary>
            /// 缓存时间
            /// </summary>
            private static DateTime cacheTime = DateTime.MinValue;

            /// <summary>
            /// 控制刷新时间time
            /// </summary>
            private static Timer timer = new Timer();

            /// <summary>
            /// timer是否开始
            /// </summary>
            private static bool timerStart = false;

            /// <summary>
            /// 锁
            /// </summary>
            private static object lockObj = new object();

            /// <summary>
            /// 构造函数
            /// </summary>
            public CachePriceParamSetting()
            {
                if (!timerStart)
                {
                    // 首次 先初始化
                    RefreshCache(true);
                    timerStart = true;
                    timer.Interval = cacheIntervalTime * 1000 * 60;
                    timer.Enabled = true;
                    timer.Elapsed += new ElapsedEventHandler(this.Timer_Elapsed);
                }
            }

            /// <summary>
            /// 刷新缓存
            /// </summary>
            /// <param name="mustRefresh">是否强制刷新缓存</param>
            public static void RefreshCache(bool mustRefresh)
            {
                if (null == priceParamSettingList || mustRefresh)
                {
                    try
                    {
                        JavaScriptSerializer serialize = new JavaScriptSerializer();
                        List<MPriceParamSetting> tempList = new List<MPriceParamSetting>();
                        lock (lockObj)
                        {
                            tempList = serialize.Deserialize<List<MPriceParamSetting>>(SupplyPriceBusinessBaseServiceHelper.GetAllPriceParamSettingJSON());
                            if (tempList != null)
                            {
                                priceParamSettingList = tempList;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        if (TrackIdManager.CurrentTrackID != null)
                        {
                            TrackIdManager.CurrentTrackID.ExceptionId = Guid.Empty;
                        }

                        AppException app = new AppException("999999", ex.Message, ex, null);
                        LogManager.Log.WriteException(app);
                    }
                }
            }

            /// <summary>
            /// 获取规则和缓存列表
            /// </summary>
            /// <returns>缓存列表</returns>
            public List<MPriceParamSetting> GetPriceParamSettingListCache()
            {
                return priceParamSettingList;
            }

            /// <summary>
            /// 定时执行 刷新缓存
            /// </summary>
            /// <param name="obj">事件</param>
            /// <param name="e">对象</param>
            private void Timer_Elapsed(object obj, ElapsedEventArgs e)
            {
                RefreshCache(true);
            }
        }

  • 相关阅读:
    ajax原理及封装
    javascript 递归调用
    CSS的五种定位方式
    vue中iframe结合window.postMessage实现父子页面间的通信
    vue将文件流的形式的图形验证码转换成图片
    路由跳转打开新窗口,传递的参数不显示在地址栏
    js判断是否是ie浏览器、360浏览器兼容模式、QQ浏览器兼容模式、搜狗浏览器兼容模式,弹出提示使用别的浏览器打开
    vue项目中使用iframe嵌入静态页面,动态获取静态页面的高度赋值给iframe的高度
    vue项目中使用iview组件中的table插件实现表头文字居中,内容文字居左
    vue前端开发实现微信支付和支付宝支付
  • 原文地址:https://www.cnblogs.com/SmartLee/p/4709258.html
Copyright © 2011-2022 走看看