feat: 用户操作静态类增加缓存

This commit is contained in:
Argo Zhang 2019-08-30 12:36:18 +08:00
parent 54e882b8b9
commit 5c13cba7e2
No known key found for this signature in database
GPG Key ID: 152E398953DDF19F
1 changed files with 10 additions and 4 deletions

View File

@ -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();
}
});
}
}