Ejemplo n.º 1
0
        public Template CreateTemplate(ControllerContext controllerContext, ICacheManager cacheManager, CacheKeyManager cacheKeyManager)
        {
            var query = cacheKeyManager.AllKeys.Select(x => new
            {
                Name = x,
                IsNull = !cacheManager.Exist(x)
            }).ToList().AsQueryable();

            if (!string.IsNullOrWhiteSpace(Name))
            {
                var name = Name.Trim();

                query = query.Where(x => x.Name.Contains(name));
            }

            var template = new AdministrationSimpleListTemplate(query)
            {
                Title = MaintCultureTextResources.CacheIndex,
                Description = MaintCultureTextResources.CacheIndexDescription,
                QueryPanelTitle = MaintCultureTextResources.PanelQuery,
                DefaultSort = "Name",
                DefaultPageSize = 10,
                Criteria = new FieldsBuilder().ForEntity(this, controllerContext).Build(),
                GlobalButtons = new List<IClickable>
                {
                    new Button(MaintCultureTextResources.Search),
                    new Button(MaintCultureTextResources.Clear, "Clear"),
                },
                Table = new Table
                {
                    Columns = new List<TableColumn>
                    {
                        new TableColumn
                        {
                            Sort = "Name",
                            Header = MaintCultureTextResources.CacheName,
                            CellTemplate = x => new Literal
                            {
                                Text = ((dynamic) x.Target).Name
                            }
                        },
                        new TableColumn
                        {
                            Sort = "Exist",
                            Header = MaintCultureTextResources.Null,
                            CellTemplate = x => new Literal
                            {
                                Text = ((dynamic) x.Target).IsNull == true ? MaintCultureTextResources.Yes : MaintCultureTextResources.No
                            }
                        }

                    }
                }
            };
            return template;
        }
Ejemplo n.º 2
0
        public MaintDomainService(CacheKeyManager cacheKeyManager, ICacheManager cacheManager, IMaintDbRepository maintDbRepository)
        {
            _cacheKeyManager = cacheKeyManager;
            _maintDbRepository = maintDbRepository;
            _cacheManager = cacheManager;

            _cacheKeyManager.RegisterCacheKey(CacheKeySystemSettings);
            _cacheKeyManager.RegisterCacheKey(CacheKeyCultures);
            _cacheKeyManager.RegisterCacheKey(CacheKeyCultureTexts);
        }
Ejemplo n.º 3
0
 public override string AuthUserInfoCacheKey(string user_uid) =>
 CacheKeyManager.AuthUserInfoKey(user_uid);
Ejemplo n.º 4
0
 public SiteController(ICacheManager cacheManager, CacheKeyManager cacheKeyManager)
 {
     _cacheManager = cacheManager;
     _cacheKeyManager = cacheKeyManager;
 }
Ejemplo n.º 5
0
 public override string AuthScopeCacheKey(string scope) =>
 CacheKeyManager.AuthScopeKey(scope);
Ejemplo n.º 6
0
 public override string AuthTokenCacheKey(string token) =>
 CacheKeyManager.AuthTokenKey(token);
Ejemplo n.º 7
0
 public override string AuthClientCacheKey(string client) =>
 CacheKeyManager.AuthClientKey(client);
Ejemplo n.º 8
0
        public async Task <ActionResult> Statics(string refresh)
        {
            return(await RunActionAsync(async() =>
            {
                var clear_cache = ValidateHelper.IsPlumpString(refresh);
                var now = DateTime.Now;
                var count = 10;
                var start = now.AddDays(-count);
                var expire = TimeSpan.FromMinutes(10);

                await this._ReqLogModelRepository.PrepareSessionAsync(async db =>
                {
                    var reqlog_query = db.Set <ReqLogModel>().AsNoTrackingQueryable();
                    var cachehit_query = db.Set <CacheHitLog>().AsNoTrackingQueryable();

                    #region 今天请求频次
                    var border = now.GetDateBorder();
                    var reqlog_groupbyhour = await this._cache.GetOrSetAsync(
                        CacheKeyManager.AuthStaticsReqLogGroupByHours(), async() =>
                    {
                        return await reqlog_query
                        .Where(x => x.CreateTime >= border.start && x.CreateTime < border.end && x.IsRemove <= 0)
                        .GroupBy(x => x.TimeHour)
                        .Select(x => new ReqLogGroupModel()
                        {
                            Hour = x.Key,
                            ReqCount = x.Count()
                        }).ToListAsync();
                    }, expire);

                    if (reqlog_groupbyhour != null)
                    {
                        for (var i = 0; i <= now.Hour; ++i)
                        {
                            var hour_data = reqlog_groupbyhour.Where(x => x.Hour == i).FirstOrDefault();
                            if (hour_data == null)
                            {
                                reqlog_groupbyhour.Add(new ReqLogGroupModel()
                                {
                                    Hour = i,
                                    ReqCount = 0
                                });
                            }
                        }
                        reqlog_groupbyhour = reqlog_groupbyhour.OrderBy(x => x.Hour).ToList();
                    }

                    ViewData[nameof(reqlog_groupbyhour)] = reqlog_groupbyhour;
                    #endregion

                    #region 请求日志
                    //请求日志按照时间分组
                    var reqlog_groupbytime = await this._cache.GetOrSetAsync(
                        CacheKeyManager.AuthStaticsReqLogGroupByDate(), async() =>
                    {
                        return await reqlog_query
                        .Where(x => x.CreateTime >= start && x.IsRemove <= 0)
                        .GroupBy(x => new { x.TimeYear, x.TimeMonth, x.TimeDay })
                        .Select(x => new ReqLogGroupModel()
                        {
                            Year = x.Key.TimeYear,
                            Month = x.Key.TimeMonth,
                            Day = x.Key.TimeDay,
                            ReqTime = x.Average(m => m.ReqTime),
                            ReqCount = x.Count()
                        }).Take(count).ToListAsync();
                    }, expire);

                    ViewData[nameof(reqlog_groupbytime)] = reqlog_groupbytime;
                    //请求日志按照控制器分组
                    var reqlog_groupbyaction = await this._cache.GetOrSetAsync(
                        CacheKeyManager.AuthStaticsReqLogGroupByAction(), async() =>
                    {
                        return await reqlog_query
                        .Where(x => x.CreateTime >= start && x.IsRemove <= 0)
                        .GroupBy(x => new { x.AreaName, x.ControllerName, x.ActionName })
                        .Select(x => new ReqLogGroupModel()
                        {
                            AreaName = x.Key.AreaName,
                            ControllerName = x.Key.ControllerName,
                            ActionName = x.Key.ActionName,
                            ReqTime = x.Average(m => m.ReqTime),
                            ReqCount = x.Count()
                        }).Take(count).ToListAsync();
                    }, expire);

                    ViewData[nameof(reqlog_groupbyaction)] = reqlog_groupbyaction;
                    #endregion

                    #region 缓存命中
                    //缓存命中按照时间分组
                    var cachehit_groupbytime = await this._cache.GetOrSetAsync(
                        CacheKeyManager.AuthStaticsCacheHitGroupByTime(), async() =>
                    {
                        return await cachehit_query
                        .Where(x => x.CreateTime >= start && x.IsRemove <= 0)
                        .GroupBy(x => new { x.TimeYear, x.TimeMonth, x.TimeDay })
                        .Select(x => new CacheHitGroupModel()
                        {
                            Year = x.Key.TimeYear,
                            Month = x.Key.TimeMonth,
                            Day = x.Key.TimeDay,
                            HitCount = x.Sum(m => m.Hit),
                            NotHitCount = x.Sum(m => m.NotHit)
                        }).Take(count).ToListAsync();
                    }, expire);

                    ViewData[nameof(cachehit_groupbytime)] = cachehit_groupbytime;
                    //缓存命中按照key分组
                    var cachehit_groupbykey = await this._cache.GetOrSetAsync(
                        CacheKeyManager.AuthStaticsCacheHitGroupByKeys(), async() =>
                    {
                        return await cachehit_query
                        .Where(x => x.CreateTime >= start && x.IsRemove <= 0)
                        .GroupBy(x => x.CacheKey).Select(x => new CacheHitGroupModel()
                        {
                            CacheKey = x.Key,
                            HitCount = x.Sum(m => m.Hit),
                            NotHitCount = x.Sum(m => m.NotHit)
                        }).Take(count).ToListAsync();
                    }, expire);

                    ViewData[nameof(cachehit_groupbykey)] = cachehit_groupbykey;
                    #endregion
                    return true;
                });
                return View();
            }));
        }
Ejemplo n.º 9
0
 public void HandleEvent(EntityUpdated <AuthClient> eventMessage)
 {
     this._cache.Remove(CacheKeyManager.AuthClientKey(eventMessage.Entity?.UID));
 }
Ejemplo n.º 10
0
 public void HandleEvent(EntityUpdated <AuthScope> eventMessage)
 {
     this._cache.Remove(CacheKeyManager.AuthScopeAllKey());
     this._cache.Remove(CacheKeyManager.AuthScopeKey(eventMessage.Entity?.UID));
 }
Ejemplo n.º 11
0
 public void HandleEvent(EntityDeleted <AuthToken> eventMessage)
 {
     this._cache.Remove(CacheKeyManager.AuthTokenKey(eventMessage.Entity?.UID));
 }