@@ -160,7 +160,7 @@ await TableWhere(x => x.Phone == createUpdateUserDto.Phone).AnyAsync())
160
160
await SugarClient . Insertable ( userJobs ) . ExecuteCommandAsync ( ) ;
161
161
162
162
//清理缓存
163
- await ClearUserCache ( user ) ;
163
+ await ClearUserCache ( user . Id ) ;
164
164
return true ;
165
165
}
166
166
@@ -176,7 +176,7 @@ public async Task<bool> DeleteAsync(HashSet<long> ids)
176
176
var users = await TableWhere ( x => ids . Contains ( x . Id ) ) . ToListAsync ( ) ;
177
177
foreach ( var user in users )
178
178
{
179
- await ClearUserCache ( user ) ;
179
+ await ClearUserCache ( user . Id ) ;
180
180
}
181
181
182
182
return await LogicDelete < User > ( x => ids . Contains ( x . Id ) ) > 0 ;
@@ -227,7 +227,7 @@ public async Task<List<ExportBase>> DownloadAsync(UserQueryCriteria userQueryCri
227
227
228
228
#region 扩展方法
229
229
230
- [ UseCache ( Expiration = 30 , KeyPrefix = GlobalConstants . CacheKey . UserInfoById ) ]
230
+ [ UseCache ( Expiration = 60 , KeyPrefix = GlobalConstants . CachePrefix . UserInfoById ) ]
231
231
public async Task < UserDto > QueryByIdAsync ( long userId )
232
232
{
233
233
var user = await TableWhere ( x => x . Id == userId ) . Includes ( x => x . Dept ) . Includes ( x => x . Roles )
@@ -241,7 +241,6 @@ public async Task<UserDto> QueryByIdAsync(long userId)
241
241
/// </summary>
242
242
/// <param name="userName">邮箱 or 用户名</param>
243
243
/// <returns></returns>
244
- [ UseCache ( Expiration = 30 , KeyPrefix = GlobalConstants . CacheKey . UserInfoByName ) ]
245
244
public async Task < UserDto > QueryByNameAsync ( string userName )
246
245
{
247
246
User user ;
@@ -326,13 +325,11 @@ public async Task<bool> UpdatePasswordAsync(UpdateUserPassDto userPassDto)
326
325
if ( isTrue )
327
326
{
328
327
//清理缓存
329
- await ApeContext . Cache . RemoveAsync ( GlobalConstants . CacheKey . UserInfoById +
328
+ await ApeContext . Cache . RemoveAsync ( GlobalConstants . CachePrefix . UserInfoById +
330
329
curUser . Id . ToString ( ) . ToMd5String16 ( ) ) ;
331
- await ApeContext . Cache . RemoveAsync ( GlobalConstants . CacheKey . UserInfoByName +
332
- curUser . Username . ToMd5String16 ( ) ) ;
333
330
334
331
//退出当前用户
335
- await ApeContext . Cache . RemoveAsync ( GlobalConstants . CacheKey . OnlineKey +
332
+ await ApeContext . Cache . RemoveAsync ( GlobalConstants . CachePrefix . OnlineKey +
336
333
ApeContext . HttpUser . JwtToken . ToMd5String16 ( ) ) ;
337
334
}
338
335
@@ -357,7 +354,7 @@ public async Task<bool> UpdateEmailAsync(UpdateUserEmailDto updateUserEmailDto)
357
354
}
358
355
359
356
var code = await ApeContext . Cache . GetAsync < string > (
360
- GlobalConstants . CacheKey . EmailCaptchaKey + updateUserEmailDto . Email . ToMd5String16 ( ) ) ;
357
+ GlobalConstants . CachePrefix . EmailCaptcha + updateUserEmailDto . Email . ToMd5String16 ( ) ) ;
361
358
if ( code . IsNullOrEmpty ( ) || ! code . Equals ( updateUserEmailDto . Code ) )
362
359
{
363
360
throw new BadRequestException ( "验证码错误" ) ;
@@ -393,7 +390,7 @@ public async Task<bool> UpdateAvatarAsync(IFormFile file)
393
390
string relativePath = Path . GetRelativePath ( prefix , avatarPath ) ;
394
391
relativePath = "/" + relativePath . Replace ( "\\ " , "/" ) ;
395
392
curUser . AvatarPath = relativePath ;
396
- await ApeContext . Cache . RemoveAsync ( GlobalConstants . CacheKey . UserInfoById +
393
+ await ApeContext . Cache . RemoveAsync ( GlobalConstants . CachePrefix . UserInfoById +
397
394
curUser . Id . ToString ( ) . ToMd5String16 ( ) ) ;
398
395
return await UpdateEntityAsync ( curUser ) ;
399
396
}
@@ -402,23 +399,17 @@ await ApeContext.Cache.RemoveAsync(GlobalConstants.CacheKey.UserInfoById +
402
399
403
400
#region 用户缓存
404
401
405
- private async Task ClearUserCache ( User user )
402
+ private async Task ClearUserCache ( long userId )
406
403
{
407
404
//清理缓存
408
- await ApeContext . Cache . RemoveAsync ( GlobalConstants . CacheKey . UserInfoById +
409
- user . Id . ToString ( ) . ToMd5String16 ( ) ) ;
410
- await ApeContext . Cache . RemoveAsync ( GlobalConstants . CacheKey . UserInfoByName +
411
- user . Username . ToMd5String16 ( ) ) ;
412
- await ApeContext . Cache . RemoveAsync ( GlobalConstants . CacheKey . UserRolesById +
413
- user . Id . ToString ( ) . ToMd5String16 ( ) ) ;
414
- await ApeContext . Cache . RemoveAsync ( GlobalConstants . CacheKey . UserJobsById +
415
- user . Id . ToString ( ) . ToMd5String16 ( ) ) ;
405
+ await ApeContext . Cache . RemoveAsync ( GlobalConstants . CachePrefix . UserInfoById +
406
+ userId . ToString ( ) . ToMd5String16 ( ) ) ;
416
407
await ApeContext . Cache . RemoveAsync (
417
- GlobalConstants . CacheKey . UserPermissionUrls + user . Id . ToString ( ) . ToMd5String16 ( ) ) ;
408
+ GlobalConstants . CachePrefix . UserPermissionUrls + userId . ToString ( ) . ToMd5String16 ( ) ) ;
418
409
await ApeContext . Cache . RemoveAsync (
419
- GlobalConstants . CacheKey . UserPermissionRoles + user . Id . ToString ( ) . ToMd5String16 ( ) ) ;
420
- await ApeContext . Cache . RemoveAsync ( GlobalConstants . CacheKey . UserBuildMenuById +
421
- user . Id . ToString ( ) . ToMd5String16 ( ) ) ;
410
+ GlobalConstants . CachePrefix . UserPermissionRoles + userId . ToString ( ) . ToMd5String16 ( ) ) ;
411
+ await ApeContext . Cache . RemoveAsync ( GlobalConstants . CachePrefix . UserMenuById +
412
+ userId . ToString ( ) . ToMd5String16 ( ) ) ;
422
413
}
423
414
424
415
#endregion
0 commit comments