Ejemplo n.º 1
0
        internal CacheItem(Func <TParam, TValue> method, Dictionary <TKey, TValue> CacheDatas)
        {
            GetCacheDataMethod = method;
            myCacheItem        = CacheItemInfoCollection <TParam, TKey, TValue> .CreateDatas(CacheDatas);

            myCacheItem.Owner = this;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 构造函数:指定同步更新间隔时间及同步时获取数据源的方法委托(单项同步)
        /// </summary>
        /// <param name="GapSpan">缓存间隔同步时间</param>
        /// <param name="method">同步获取数据的委托,只获取缓存中某一项</param>
        /// <param name="CacheDatas">初始要缓存的值</param>
        internal CacheItem(TimeSpan GapSpan, Func <TParam, TValue> method, Dictionary <TKey, TValue> CacheDatas)
        {
            myCacheItem = CacheItemInfoCollection <TParam, TKey, TValue> .CreateDatas(CacheDatas);

            myCacheItem.Owner = this;

            myCacheItem.GapSpanTime = GapSpan;
            GetCacheDataMethod      = method;
        }
Ejemplo n.º 3
0
        public void Reload(Dictionary <TKey, TValue> datas)
        {
            CacheItemInfoCollection <TParam, TKey, TValue> tmp = CacheItemInfoCollection <TParam, TKey, TValue> .CreateDatas(datas);

            tmp.Owner = this;
            lock (myCacheItem)
            {
                myCacheItem.Clear();
                myCacheItem = tmp;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 同步缓存中的数据,注意,这里并不是实际同步,而是自动标记缓存项的过期时间
        /// </summary>
        private void SyncData()
        {
            if (GetAllMethod != null)
            {
                Dictionary <TKey, TValue> o = GetAllMethod();
                if (o != null)
                {//未实际获取到数据
                    CacheItemInfoCollection <TParam, TKey, TValue> datas = CacheItemInfoCollection <TParam, TKey, TValue> .CreateDatas(o);

                    datas.Owner = this;
                    lock (myCacheItem)
                    {
                        myCacheItem = datas;
                    }
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 构造函数:指定同步间隔时间及所有数据同步的委托,只适合那种更新较快的项
        /// </summary>
        /// <param name="GapSpan"></param>
        /// <param name="method"></param>
        internal CacheItem(TimeSpan GapSpan, Func <Dictionary <TKey, TValue> > method)
        {
            GetAllMethod = method;
            if (method != null)
            {
                myCacheItem = CacheItemInfoCollection <TParam, TKey, TValue> .CreateDatas(method());
            }
            else
            {
                myCacheItem = new CacheItemInfoCollection <TParam, TKey, TValue>();
            }

            myCacheItem.Owner = this;

            syncUtil = ThreadSvrUtil.CreateSvrUtil(GapSpan, SyncData);
            //自动启动同步服务
            syncUtil.Start();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 构造函数:指定同步间隔时间及所有数据同步的委托,只适合那种更新较快的项
        /// 通过定时表达式创建定时激活器
        /// 定时器设置格式如下:
        /// 1、定时触发:0|h|1,表示按每小时激活,0|m|1 表示按每分钟激活,0|s|1 表示按每秒钟激活,0|ms|1 表示按每毫秒激活
        /// 2、时点触发:1|17:30;17:12;02:36
        /// </summary>
        /// <param name="GapSpanExp"></param>
        /// <returns></returns>
        internal CacheItem(string GapSpanExp, Func <Dictionary <TKey, TValue> > method, Dictionary <TKey, TValue> items)
        {
            GetAllMethod = method;
            if (items != null)
            {
                myCacheItem = CacheItemInfoCollection <TParam, TKey, TValue> .CreateDatas(items);
            }
            else
            {
                myCacheItem = new CacheItemInfoCollection <TParam, TKey, TValue>();
            }
            myCacheItem.Owner = this;

            ThreadTimer timer = ThreadTimer.CreateThreadTimerByExp(GapSpanExp);

            timer.Method = SyncData;
            syncUtil     = new ThreadSvrUtil(timer);
            //自动启动同步服务
            syncUtil.Start();
        }