Exemple #1
0
        public async Task <bool> AddListAsync <T>(IEnumerable <T> data)
        {
            if (data == null || data.Count() < 1 || !IsCachingServer)
            {
                return(false);
            }
            try
            {
                List <Tuple <string, T> > objList    = new List <Tuple <string, T> >();
                PropertyInfo[]            properties = typeof(T).GetProperties();
                string pattern = Helper.GetClassName <T>() + ":";

                foreach (var obj in data)
                {
                    var key = pattern + properties[0].GetValue(obj).ToString();
                    objList.Add(Tuple.Create(key, obj));
                }

                //Keys
                var keys = await Sut.SearchKeysAsync(pattern);

                if (keys.Count() > 0)
                {
                    await Sut.RemoveAllAsync(keys);
                }

                //Add
                if (TimeExpried > 0)
                {
                    return(await Sut.AddAllAsync(objList, TimeSpan.FromMinutes(TimeExpried)));
                }
                else
                {
                    return(await Sut.AddAllAsync(objList));
                }
            }
            catch (Exception ex)
            {
                LogManager.Logger.LogError(ex);
                return(false);
            }
        }
Exemple #2
0
 public Task <bool> AddAllAsync <T>(IList <Tuple <string, T> > items)
 {
     return(_clientExt.AddAllAsync(items));
 }