Skip to content

Commit d65fd2d

Browse files
author
1877682825@qq.com
committed
增加缓存
1 parent 45074b4 commit d65fd2d

File tree

6 files changed

+42
-22
lines changed

6 files changed

+42
-22
lines changed

ant.mgr/Repository/Repository/AdminRepository/CommonRespository.cs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using AntData.ORM;
2-
using AntData.ORM.Data;
1+
using AntData.ORM.Data;
32
using AntData.ORM.Mapping;
43
using Autofac.Annotation;
54
using Castle.DynamicProxy;
@@ -10,14 +9,12 @@
109
using Repository.Interface;
1110
using ServicesModel;
1211
using System;
12+
using System.Collections.Concurrent;
1313
using System.Collections.Generic;
1414
using System.IO;
1515
using System.Linq;
1616
using System.Reflection;
17-
using System.Threading.Tasks;
1817
using ViewModels.Reuqest;
19-
using Infrastructure;
20-
using System.Text;
2118

2219
namespace Repository
2320
{
@@ -28,21 +25,27 @@ namespace Repository
2825
public class CommonRespository : BaseRepository, ICommonRespository
2926
{
3027

28+
private static string _dbTableAndColumnsCache = string.Empty;
29+
private static List<CodeGenTable> _dbTableCache = null;
30+
private static readonly ConcurrentDictionary<string, List<CodeGenField>> _dbColumnsCache = new ConcurrentDictionary<string, List<CodeGenField>>();
31+
3132

3233
/// <summary>
3334
/// 获取所有的Table和Columns
3435
/// </summary>
3536
/// <returns></returns>
3637
public string GetDbTablesAndColumns()
3738
{
39+
if (!string.IsNullOrEmpty(_dbTableAndColumnsCache)) return _dbTableAndColumnsCache;
3840
Dictionary<string, List<string>> result = new Dictionary<string, List<string>>();
3941
List<string> tables = this.DB.Query<string>("show tables").ToList();
4042
foreach (var table in tables)
4143
{
4244
var columns = getAllFields(table);
4345
result.Add(table, columns);
4446
}
45-
return JsonConvert.SerializeObject(result);
47+
_dbTableAndColumnsCache = JsonConvert.SerializeObject(result);
48+
return _dbTableAndColumnsCache;
4649
}
4750

4851
/// <summary>
@@ -51,8 +54,12 @@ public string GetDbTablesAndColumns()
5154
/// <returns></returns>
5255
public List<CodeGenTable> GetDbTables()
5356
{
54-
55-
return this.GetDbTabless();
57+
if (_dbTableCache != null)
58+
{
59+
return _dbTableCache;
60+
}
61+
_dbTableCache = this.GetDbTabless();
62+
return _dbTableCache;
5663
}
5764

5865
/// <summary>
@@ -62,7 +69,10 @@ public List<CodeGenTable> GetDbTables()
6269
/// <returns></returns>
6370
public List<CodeGenField> GetDbTablesColumns(string tableName)
6471
{
65-
return this.GetDbModels(tableName);
72+
if (_dbColumnsCache.TryGetValue(tableName, out var cache)) return cache;
73+
cache = this.GetDbModels(tableName);
74+
_dbColumnsCache.TryAdd(tableName, cache);
75+
return cache;
6676
}
6777

6878

ant.mgr/Repository/Repository/AdminRepository/MenuRespository.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Repository.Interface;
1111
using ServicesModel;
1212
using System;
13+
using System.Collections.Concurrent;
1314
using System.Collections.Generic;
1415
using System.Linq;
1516
using DbModel;
@@ -23,6 +24,9 @@ namespace Repository
2324
[Bean(typeof(IMenuRespository), Interceptor = typeof(AsyncInterceptor))]
2425
public class MenuRespository : BaseRepository<SystemMenu>, IMenuRespository
2526
{
27+
28+
private static readonly ConcurrentDictionary<string, List<SystemMenuSM>> _cache = new ConcurrentDictionary<string, List<SystemMenuSM>>();
29+
2630
/// <summary>
2731
/// Autofac属性注入
2832
/// </summary>
@@ -429,7 +433,7 @@ private void addActionChildrenTwo(List<SystemMenuSM> sysActionSMList, BigInteger
429433
}
430434
}
431435

432-
436+
433437
private List<SystemMenuSM> GetAllRightsMenusTwo(string eid, string menuRights, bool isGod = false)
434438
{
435439
var isGlod = GlobalSetting.GoldList.Contains(eid) || isGod;
@@ -492,14 +496,18 @@ private List<SystemMenuSM> GetActionsList(string url)
492496
if (string.IsNullOrEmpty(url)) return new List<SystemMenuSM>();
493497
if (url.StartsWith("http")) return new List<SystemMenuSM>();
494498

499+
if (_cache.TryGetValue(url, out var cache)) return cache;
495500
var body = ViewRenderService.RenderToStringAsync(url.Replace("~/", ""), null).ConfigureAwait(false).GetAwaiter().GetResult();
496501
var actionList = body.GetValueAndNameByClass("action-id", "action-name", "authorization");
497-
var result = actionList.Select(r => new SystemMenuSM
502+
cache = actionList.Select(r => new SystemMenuSM
498503
{
499504
ActionId = r.Key,
500505
Name = r.Value
501506
}).ToList();
502-
return result;
507+
508+
_cache.TryAdd(url, cache);
509+
510+
return cache;
503511
}
504512

505513
#endregion

ant.mgr/mgr.core/Areas/Admin/Controllers/HomeController.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ public ActionResult Index()
4040
}
4141

4242

43-
public ActionResult DashBord()
44-
{
45-
return Content("DashBord");
46-
}
4743

4844
#region 菜单
4945

ant.mgr/mgr.core/Areas/Admin/Views/Home/DashBord.cshtml

Lines changed: 0 additions & 4 deletions
This file was deleted.

ant.mgr/mgr.core/Controller/HomeController.cs renamed to ant.mgr/mgr.core/Controllers/HomeController.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,15 @@ public IActionResult Index()
1212
{
1313
return RedirectToAction("Index", "Home", new { area = "Admin" });
1414
}
15+
16+
/// <summary>
17+
/// 首页
18+
/// </summary>
19+
/// <returns></returns>
20+
21+
public ActionResult DashBord()
22+
{
23+
return Content("DashBord");
24+
}
1525
}
1626
}

ant.mgr/mgr.core/Views/Shared/_HomeLayout.cshtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
</li>
4141
</li>
4242
<li>
43-
<a class="J_menuItem" href="~/Admin/Home/DashBord" data-id="Home/DashBord"><i class="fa fa-home"></i> <span class="nav-label">首页</span></a>
43+
<a class="J_menuItem" href="~/Home/DashBord" data-id="Home/DashBord"><i class="fa fa-home"></i> <span class="nav-label">首页</span></a>
4444
</li>
4545
@await Component.InvokeAsync("MenuHeader")
4646
</ul>
@@ -111,7 +111,7 @@
111111
<a href="@Url.Page("/Account/Logout", new { area = "Admin" })" class="roll-nav roll-right J_tabExit"><i class="fa fa fa-sign-out"></i> 退出</a>
112112
</div>
113113
<div class="row J_mainContent" id="content-main">
114-
<iframe class="J_iframe" name="iframe0" width="100%" height="100%" src="~/Admin/Home/DashBord" frameborder="0" data-id="Admin/Home/DashBord" seamless></iframe>
114+
<iframe class="J_iframe" name="iframe0" width="100%" height="100%" src="~/Home/DashBord" frameborder="0" data-id="Home/DashBord" seamless></iframe>
115115
</div>
116116
<div class="footer">
117117
<div class="pull-right">

0 commit comments

Comments
 (0)