Skip to content

Commit

Permalink
[代码优化](v2.6):缓存优化
Browse files Browse the repository at this point in the history
  • Loading branch information
elunez committed Dec 21, 2020
1 parent 81dd91f commit 2a3e4cd
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 21 deletions.
11 changes: 0 additions & 11 deletions eladmin-common/src/main/java/me/zhengjie/utils/CacheKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,10 @@
*/
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_NAME = "user::username:";
/**
* 数据
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotBlank;
import java.io.File;
Expand Down Expand Up @@ -120,10 +119,6 @@ public void update(User resources) {
redisUtils.del(CacheKey.MENU_USER + resources.getId());
redisUtils.del(CacheKey.ROLE_AUTH + resources.getId());
}
// 如果用户名称修改
if(!resources.getUsername().equals(user.getUsername())){
redisUtils.del("user::username:" + user.getUsername());
}
// 如果用户被禁用,则清除用户登录信息
if(!resources.getEnabled()){
onlineUserService.kickOutForUsername(resources.getUsername());
Expand Down Expand Up @@ -170,7 +165,6 @@ public void delete(Set<Long> ids) {
}

@Override
@Cacheable(key = "'username:' + #p0")
public UserDto findByName(String userName) {
User user = userRepository.findByUsername(userName);
if (user == null) {
Expand All @@ -184,7 +178,6 @@ public UserDto findByName(String userName) {
@Transactional(rollbackFor = Exception.class)
public void updatePass(String username, String pass) {
userRepository.updatePass(username, pass, new Date());
redisUtils.del("user::username:" + username);
flushCache(username);
}

Expand All @@ -201,7 +194,6 @@ public Map<String, String> updateAvatar(MultipartFile multipartFile) {
FileUtil.del(oldPath);
}
@NotBlank String username = user.getUsername();
redisUtils.del(CacheKey.USER_NAME + username);
flushCache(username);
return new HashMap<String, String>(1) {{
put("avatar", file.getName());
Expand All @@ -212,7 +204,6 @@ public Map<String, String> updateAvatar(MultipartFile multipartFile) {
@Transactional(rollbackFor = Exception.class)
public void updateEmail(String username, String email) {
userRepository.updateEmail(username, email);
redisUtils.del(CacheKey.USER_NAME + username);
flushCache(username);
}

Expand Down Expand Up @@ -243,7 +234,6 @@ public void download(List<UserDto> queryAll, HttpServletResponse response) throw
*/
public void delCaches(Long id, String username) {
redisUtils.del(CacheKey.USER_ID + id);
redisUtils.del(CacheKey.USER_NAME + username);
flushCache(username);
}

Expand Down

0 comments on commit 2a3e4cd

Please sign in to comment.