Commit 0972d902 authored by 技术部-任文超's avatar 技术部-任文超

添加共享内存,解决跨JVM线程无法同步问题

parent fab89b05
......@@ -5,6 +5,8 @@ import cn.quantgroup.xyqb.repository.IUserAttachedRepository;
import cn.quantgroup.xyqb.service.user.UserCenterService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import java.sql.Timestamp;
......@@ -21,11 +23,13 @@ public class UserCenterServiceImpl implements UserCenterService {
private IUserAttachedRepository userAttachedRepository;
@Override
@Cacheable(value = "userAttachedCache", key = "'xyqbUserAttached' + #userId", unless = "#result == null", cacheManager = "cacheManager")
public UserAttached searchUserAttachedByUserId(long userId) {
return userAttachedRepository.findByUserId(userId);
}
@Override
@CacheEvict(value = "userAttachedCache", key = "'xyqbUserAttached' + #userId", cacheManager = "cacheManager")
public UserAttached saveUserAvatar(long userId, String avatar) {
UserAttached userAttached = userAttachedRepository.findByUserId(userId);
if(Objects.isNull(userAttached)){
......@@ -40,6 +44,7 @@ public class UserCenterServiceImpl implements UserCenterService {
}
@Override
@CacheEvict(value = "userAttachedCache", key = "'xyqbUserAttached' + #userId", cacheManager = "cacheManager")
public UserAttached saveUserNick(long userId, String nick) {
UserAttached userAttached = userAttachedRepository.findByUserId(userId);
if(Objects.isNull(userAttached)){
......@@ -62,7 +67,7 @@ public class UserCenterServiceImpl implements UserCenterService {
* @return
*/
private synchronized UserAttached createUserAttached(Long userId, String avatar, String nick) {
UserAttached userAttached = userAttachedRepository.findByUserId(userId);
UserAttached userAttached = this.searchUserAttachedByUserId(userId);
// 更新实例
userAttached = Optional.ofNullable(userAttached).orElse(new UserAttached());
Timestamp now = new Timestamp(System.currentTimeMillis());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment