Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Eladmin
Commits
2a3e4cd9
Commit
2a3e4cd9
authored
Dec 21, 2020
by
zhengjie
Browse files
[代码优化](v2.6):缓存优化
parent
81dd91f5
Changes
2
Hide whitespace changes
Inline
Side-by-side
eladmin-common/src/main/java/me/zhengjie/utils/CacheKey.java
View file @
2a3e4cd9
...
@@ -22,21 +22,10 @@ package me.zhengjie.utils;
...
@@ -22,21 +22,10 @@ package me.zhengjie.utils;
*/
*/
public
interface
CacheKey
{
public
interface
CacheKey
{
/**
* 内置 用户、岗位、应用、菜单、角色 相关key
*/
String
USER_MODIFY_TIME_KEY
=
"user:modify:time:key:"
;
String
APP_MODIFY_TIME_KEY
=
"app:modify:time:key:"
;
String
JOB_MODIFY_TIME_KEY
=
"job:modify:time:key:"
;
String
MENU_MODIFY_TIME_KEY
=
"menu:modify:time:key:"
;
String
ROLE_MODIFY_TIME_KEY
=
"role:modify:time:key:"
;
String
DEPT_MODIFY_TIME_KEY
=
"dept:modify:time:key:"
;
/**
/**
* 用户
* 用户
*/
*/
String
USER_ID
=
"user::id:"
;
String
USER_ID
=
"user::id:"
;
String
USER_NAME
=
"user::username:"
;
/**
/**
* 数据
* 数据
*/
*/
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java
View file @
2a3e4cd9
...
@@ -37,7 +37,6 @@ import org.springframework.data.domain.Pageable;
...
@@ -37,7 +37,6 @@ import org.springframework.data.domain.Pageable;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.validation.constraints.NotBlank
;
import
javax.validation.constraints.NotBlank
;
import
java.io.File
;
import
java.io.File
;
...
@@ -120,10 +119,6 @@ public class UserServiceImpl implements UserService {
...
@@ -120,10 +119,6 @@ public class UserServiceImpl implements UserService {
redisUtils
.
del
(
CacheKey
.
MENU_USER
+
resources
.
getId
());
redisUtils
.
del
(
CacheKey
.
MENU_USER
+
resources
.
getId
());
redisUtils
.
del
(
CacheKey
.
ROLE_AUTH
+
resources
.
getId
());
redisUtils
.
del
(
CacheKey
.
ROLE_AUTH
+
resources
.
getId
());
}
}
// 如果用户名称修改
if
(!
resources
.
getUsername
().
equals
(
user
.
getUsername
())){
redisUtils
.
del
(
"user::username:"
+
user
.
getUsername
());
}
// 如果用户被禁用,则清除用户登录信息
// 如果用户被禁用,则清除用户登录信息
if
(!
resources
.
getEnabled
()){
if
(!
resources
.
getEnabled
()){
onlineUserService
.
kickOutForUsername
(
resources
.
getUsername
());
onlineUserService
.
kickOutForUsername
(
resources
.
getUsername
());
...
@@ -170,7 +165,6 @@ public class UserServiceImpl implements UserService {
...
@@ -170,7 +165,6 @@ public class UserServiceImpl implements UserService {
}
}
@Override
@Override
@Cacheable
(
key
=
"'username:' + #p0"
)
public
UserDto
findByName
(
String
userName
)
{
public
UserDto
findByName
(
String
userName
)
{
User
user
=
userRepository
.
findByUsername
(
userName
);
User
user
=
userRepository
.
findByUsername
(
userName
);
if
(
user
==
null
)
{
if
(
user
==
null
)
{
...
@@ -184,7 +178,6 @@ public class UserServiceImpl implements UserService {
...
@@ -184,7 +178,6 @@ public class UserServiceImpl implements UserService {
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
updatePass
(
String
username
,
String
pass
)
{
public
void
updatePass
(
String
username
,
String
pass
)
{
userRepository
.
updatePass
(
username
,
pass
,
new
Date
());
userRepository
.
updatePass
(
username
,
pass
,
new
Date
());
redisUtils
.
del
(
"user::username:"
+
username
);
flushCache
(
username
);
flushCache
(
username
);
}
}
...
@@ -201,7 +194,6 @@ public class UserServiceImpl implements UserService {
...
@@ -201,7 +194,6 @@ public class UserServiceImpl implements UserService {
FileUtil
.
del
(
oldPath
);
FileUtil
.
del
(
oldPath
);
}
}
@NotBlank
String
username
=
user
.
getUsername
();
@NotBlank
String
username
=
user
.
getUsername
();
redisUtils
.
del
(
CacheKey
.
USER_NAME
+
username
);
flushCache
(
username
);
flushCache
(
username
);
return
new
HashMap
<
String
,
String
>(
1
)
{{
return
new
HashMap
<
String
,
String
>(
1
)
{{
put
(
"avatar"
,
file
.
getName
());
put
(
"avatar"
,
file
.
getName
());
...
@@ -212,7 +204,6 @@ public class UserServiceImpl implements UserService {
...
@@ -212,7 +204,6 @@ public class UserServiceImpl implements UserService {
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
updateEmail
(
String
username
,
String
email
)
{
public
void
updateEmail
(
String
username
,
String
email
)
{
userRepository
.
updateEmail
(
username
,
email
);
userRepository
.
updateEmail
(
username
,
email
);
redisUtils
.
del
(
CacheKey
.
USER_NAME
+
username
);
flushCache
(
username
);
flushCache
(
username
);
}
}
...
@@ -243,7 +234,6 @@ public class UserServiceImpl implements UserService {
...
@@ -243,7 +234,6 @@ public class UserServiceImpl implements UserService {
*/
*/
public
void
delCaches
(
Long
id
,
String
username
)
{
public
void
delCaches
(
Long
id
,
String
username
)
{
redisUtils
.
del
(
CacheKey
.
USER_ID
+
id
);
redisUtils
.
del
(
CacheKey
.
USER_ID
+
id
);
redisUtils
.
del
(
CacheKey
.
USER_NAME
+
username
);
flushCache
(
username
);
flushCache
(
username
);
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment