feat: 用户操作静态类增加缓存
This commit is contained in:
parent
54e882b8b9
commit
5c13cba7e2
|
@ -1,4 +1,5 @@
|
|||
using MongoDB.Driver;
|
||||
using Longbow.Cache;
|
||||
using MongoDB.Driver;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
@ -7,10 +8,15 @@ namespace Bootstrap.Client.DataAccess.MongoDB
|
|||
class UserHelper
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// 获取所有用户缓存数据键值
|
||||
/// </summary>
|
||||
public const string RetrieveUsersDataKey = "UserHelper-RetrieveUsers";
|
||||
|
||||
/// <summary>
|
||||
/// 查询所有用户
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<User> Retrieves()
|
||||
public static IEnumerable<User> Retrieves() => CacheManager.GetOrAdd(RetrieveUsersDataKey, key =>
|
||||
{
|
||||
var project = Builders<User>.Projection.Include(u => u.Id)
|
||||
.Include(u => u.UserName)
|
||||
|
@ -19,6 +25,6 @@ namespace Bootstrap.Client.DataAccess.MongoDB
|
|||
.Include(u => u.Roles)
|
||||
.Include(u => u.ApprovedTime);
|
||||
return DbManager.Users.Find(user => user.ApprovedTime != DateTime.MinValue).Project<User>(project).ToList();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue