示例#1
0
        /// <summary>获取 或 增加 配置项</summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public CacheSetting GetOrAdd(String name)
        {
            var ms   = Items ?? new CacheSetting[0];
            var item = ms.FirstOrDefault(e => e?.Name == name);

            if (item != null)
            {
                return(item);
            }

            // 如果找不到,则增加
            item = new CacheSetting {
                Name = name
            };
            //Items.Add(item);
            lock (ms)
            {
                var list = new List <CacheSetting>(ms)
                {
                    item
                };

                Items = list.ToArray();
            }

            return(item);
        }
示例#2
0
文件: MemoryCache.cs 项目: toby2o12/X
 /// <summary>初始化配置</summary>
 /// <param name="set"></param>
 protected override void Init(CacheSetting set)
 {
     if (clearTimer == null)
     {
         var period = 60;
         clearTimer = new TimerX(RemoveNotAlive, null, period * 1000, period * 1000);
     }
 }
示例#3
0
文件: CacheSetting.cs 项目: xchit/X
        /// <summary>获取 或 增加 配置项</summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public CacheSetting GetOrAdd(String name)
        {
            var item = Items.FirstOrDefault(e => e.Name == name);

            if (item != null)
            {
                return(item);
            }

            // 如果找不到,则增加
            item = new CacheSetting {
                Name = name
            };
            Items.Add(item);

            return(item);
        }
示例#4
0
文件: Redis.cs 项目: mazhongbin/X
        /// <summary>初始化</summary>
        /// <param name="set"></param>
        protected override void Init(CacheSetting set)
        {
            var config = set?.Value;

            if (config.IsNullOrEmpty())
            {
                return;
            }

            var dic = config.SplitAsDictionary("=", ";");

            if (dic.Count > 0)
            {
                Server   = dic["Server"];
                Password = dic["Password"];
                Db       = dic["Db"].ToInt();
            }
        }
示例#5
0
文件: Cache.cs 项目: toby2o12/X
        /// <summary>创建缓存实例</summary>
        /// <param name="set">配置项</param>
        /// <returns></returns>
        public static ICache Create(CacheSetting set)
        {
            return(_cache.GetOrAdd(set.Name, k =>
            {
                var id = set.Provider;

                var type = ObjectContainer.Current.ResolveType <ICache>(id);
                if (type == null)
                {
                    throw new ArgumentNullException(nameof(type), "找不到名为[{0}]的缓存实现[{1}]".F(set.Name, id));
                }

                var ic = type.CreateInstance() as ICache;
                if (ic is Cache ic2)
                {
                    ic2.Init(set);
                }

                return ic;
            }));
        }
示例#6
0
        /// <summary>获取 或 增加 配置项</summary>
        /// <param name="name">名称</param>
        /// <param name="provider">提供者</param>
        /// <param name="value">配置</param>
        /// <returns></returns>
        public CacheSetting GetOrAdd(String name, String provider = null, String value = null)
        {
            var ms   = Items ?? new CacheSetting[0];
            var item = ms.FirstOrDefault(e => e?.Name == name);

            if (item != null)
            {
                return(item);
            }

            // 如果找不到,则增加
            item = new CacheSetting {
                Name = name
            };
            //Items.Add(item);
            lock (ms)
            {
                var list = new List <CacheSetting>(ms)
                {
                    item
                };

                Items = list.ToArray();
            }

            // 添加提供者并保存
            if (!provider.IsNullOrEmpty())
            {
                item.Provider = provider;
                item.Value    = value;

                Save();
            }

            return(item);
        }
示例#7
0
文件: Cache.cs 项目: toby2o12/X
 /// <summary>初始化配置</summary>
 /// <param name="set"></param>
 protected virtual void Init(CacheSetting set)
 {
 }