Example #1
0
        public static void Remove(string key)
        {
            if (IsMemoryCacheClient)
            {
                var pool   = ClientRedis.GetClient(key);
                var client = null as IRedisClient;
                try
                {
                    client = pool.GetClient();
                    if (client != null)
                    {
                        client.Remove(key);
                    }
                }
                finally
                {
                    if (pool != null && client != null)
                    {
                        pool.DisposeClient(client as RedisNativeClient);
                    }
                }

                //ClientRedis.GetClient(key).Remove(key);
            }
            else
            {
                var _tmp = null as ValueContanier;
                CurrentValues.TryRemove(key, out _tmp);
            }
        }
Example #2
0
        public static void Set(string key, ValueContanier contanier)
        {
            if (string.IsNullOrEmpty(key))
            {
                return;
            }

            if (IsMemoryCacheClient)
            {
                try
                {
                    if (contanier.cache == DateTime.MinValue)
                    {
                        ClientRedis.Set(key, contanier.obj.Значение);
                    }
                    else
                    {
                        ClientRedis.Set(key, contanier.obj.Значение, contanier.cache);
                    }
                }
                catch (Exception ex)
                {
                    ConfigurationClient.WindowsLog("MemoryCache:Set", "", "system", key, ex.ToString());
                }

                //var p = key.Split(':');
                //var baseName = p[0];
                //var id_node = Convert.ToDecimal(p[1]);
                //var attrName = p[2];

                //if ("такси".Equals(baseName))
                //{
                //    var dic = new Dictionary<string, object>();
                //    dic.Add(attrName, contanier.obj.Значение);
                //    var guid = new Guid(new DataClient().ПолучитьЗначение<string>(id_node, "GuidCode", Хранилище.Оперативное, baseName));

                //    HBaseCore.ClientHbase.SetAsinc(baseName, new HBaseCore.Row(guid, dic, new string[] { id_node.ToString("f0") }.ToList()));
                //}
            }
            else
            {
                CurrentValues.AddOrUpdate(key, contanier, (k, e) => e = contanier);
            }
        }
Example #3
0
        public static ValueContanier Get(string key)
        {
            if (string.IsNullOrEmpty(key))
            {
                return(null);
            }

            if (IsMemoryCacheClient)
            {
                try
                {
                    var _tmp = ClientRedis.Get(key);
                    if (_tmp != null)
                    {
                        return(new ValueContanier()
                        {
                            obj = new Value()
                            {
                                Значение = Convert.IsDBNull(_tmp) ? null : _tmp
                            }
                        });
                    }
                }
                catch (Exception ex)
                {
                    ConfigurationClient.WindowsLog("MemoryCache:Get", "", "system", key, ex.ToString());
                }
            }
            else
            {
                var _tmp = null as ValueContanier;
                if (CurrentValues.TryGetValue(key, out _tmp))
                {
                    _tmp.cache = DateTime.Now.Add(Timeout);
                    return(_tmp);
                }
            }
            return(null);
        }
Example #4
0
        public static Dictionary <string, ValueContanier> Get(params string[] key)
        {
            var result = new Dictionary <string, ValueContanier>();

            if (key != null && key.Length > 0)
            {
                if (IsMemoryCacheClient)
                {
                    try
                    {
                        foreach (var item in ClientRedis.Get(key))
                        {
                            if (item.Value != null)
                            {
                                result.Add(item.Key, new ValueContanier()
                                {
                                    obj = new Value()
                                    {
                                        Значение = Convert.IsDBNull(item.Value) ? null : item.Value
                                    }
                                });
                            }
                        }

                        //var _tmp = ClientRedis.Get(key);
                        //if (_tmp != null)
                        //{
                        //    return new ValueContanier()
                        //    {
                        //        obj = new Value()
                        //        {
                        //            Значение = _tmp
                        //        }
                        //    };
                        //}
                    }
                    catch (Exception ex)
                    {
                        ConfigurationClient.WindowsLog("MemoryCache:Get", "", "system", key, ex.ToString());
                    }
                }
                else
                {
                    foreach (var item in key)
                    {
                        if (string.IsNullOrEmpty(item))
                        {
                            continue;
                        }

                        var _tmp = null as ValueContanier;
                        if (CurrentValues.TryGetValue(item, out _tmp))
                        {
                            _tmp.cache = DateTime.Now.Add(Timeout);
                            if (!result.ContainsKey(item))
                            {
                                result.Add(item, _tmp);
                            }
                        }
                    }
                }
            }
            return(result);
        }