Beispiel #1
0
        /// <summary>
        ///     添加统计
        /// </summary>
        /// <param name="sql">dbBuilder.ToString():唯一标识</param>
        /// <param name="dataType">数据类型</param>
        private static string CreateKey(string sql, enumDataType dataType)
        {
            #region 移除失效时间
            // 移除失效的时间
            DataStatisticsList.ForEach(o => o.LstActiveAt.RemoveAll(t => DateTime.Now > t.AddMinutes(CacheConfigs.ConfigInfo.VisitTime)));

            // 移除无时间统计的项
            DataStatisticsList.RemoveAll(o => o.Value == null && o.LstActiveAt.Count() == 0);
            // 重置加入缓存时间
            var lst = DataStatisticsList.Where(o => o.Value == null).ToList();
            for (var i = 0; i < lst.Count; i++)
            {
                lst[i].JoinCacheAt = DateTime.MinValue;
            }
            #endregion

            var key = Encrypt.MD5(dataType.GetName() + sql).Substring(8, 16);

            // 加入统计
            var cache = DataStatisticsList.FirstOrDefault(o => o.Key == key);
            if (cache == null)
            {
                cache = new DataCache {
                    Key = key, DataType = dataType, LstActiveAt = new List <DateTime>()
                };
                DataStatisticsList.Add(cache);
            }
            cache.LstActiveAt.Add(DateTime.Now);

            return(key);
        }