diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/UserService.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/UserService.cs index 662960ba..d1145e7a 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/UserService.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/UserService.cs @@ -45,12 +45,9 @@ class UserService : IUser return isAuth; } - /// - /// - /// - /// - /// - public User? GetUserByUserName(string? userName) => string.IsNullOrEmpty(userName) ? null : Database.FirstOrDefault("Where UserName = @0", userName); + private const string UserServiceGetUserByUserNameCacheKey = "UserService-GetUserByUserName"; + + public User? GetUserByUserName(string? userName) => CacheManager.GetOrAdd($"{UserServiceGetUserByUserNameCacheKey}-{userName}", entry => string.IsNullOrEmpty(userName) ? null : Database.FirstOrDefault("Where UserName = @0", userName)); private const string UserServiceGetAppsByUserNameCacheKey = "UserService-GetAppsByUserName"; @@ -173,17 +170,41 @@ class UserService : IUser /// /// /// - public bool SaveDisplayName(string userName, string displayName) => Database.Update("set DisplayName = @1 where UserName = @0", userName, displayName) == 1; + public bool SaveDisplayName(string userName, string displayName) + { + var ret = Database.Update("set DisplayName = @1 where UserName = @0", userName, displayName) == 1; + if (ret) + { + CacheManager.Clear(); + } + return ret; + } /// /// /// - public bool SaveTheme(string userName, string theme) => Database.Update("set Css = @1 where UserName = @0", userName, theme) == 1; + public bool SaveTheme(string userName, string theme) + { + var ret = Database.Update("set Css = @1 where UserName = @0", userName, theme) == 1; + if (ret) + { + CacheManager.Clear(); + } + return ret; + } /// /// /// - public bool SaveLogo(string userName, string? logo) => Database.Update("set Icon = @1 where UserName = @0", userName, logo) == 1; + public bool SaveLogo(string userName, string? logo) + { + var ret = Database.Update("set Icon = @1 where UserName = @0", userName, logo) == 1; + if (ret) + { + CacheManager.Clear(); + } + return ret; + } /// /// 创建手机用户 @@ -296,7 +317,11 @@ class UserService : IUser public bool SaveApp(string userName, string app) { - Database.Update("Set App = @1 Where UserName = @0", userName, app); - return true; + var ret = Database.Update("Set App = @1 Where UserName = @0", userName, app) == 1; + if (ret) + { + CacheManager.Clear(); + } + return ret; } }