Commit 4a21fdbb by hweeeeeei

优化:根据id查询会话调用频率较高,增加redis缓存,有修改数据库时能同步清空redis该会话数据

parent 55d3156d
......@@ -104,6 +104,14 @@ public interface ImConversationService extends BaseService<ImConversation> {
ImConversationQueryVo getImConversationById(Long id);
/**
* 删除redis中该会话的缓存
*
* @param id
*/
void deleteCacheImConversationById(Long id);
/**
* 获取分页对象
*
* @param imConversationPageParam
......
......@@ -45,6 +45,9 @@ import io.geekidea.springbootplus.framework.shiro.util.JwtUtil;
import io.geekidea.springbootplus.framework.shiro.util.SnowflakeUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -62,6 +65,7 @@ import java.util.Map;
*/
@Slf4j
@Service
@CacheConfig(cacheNames = "convstn")
public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMapper, ImConversation> implements ImConversationService {
@Autowired
......@@ -621,6 +625,9 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
imConversationById.setName(imConversationNameUpdate.getName());
boolean b = imConversationService.updateById(imConversationById);
// 删除redis中该会话的缓存
deleteCacheImConversationById(imConversationNameUpdate.getConversationId());
if (b) {
// 下发群名称变动事件
......@@ -703,6 +710,10 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
imConversationById.setAttributes(attributes);
boolean b = imConversationService.updateById(imConversationById);
// 删除redis中该会话的缓存
deleteCacheImConversationById(imConversationAttrUpdate.getConversationId());
if (b) {
......@@ -785,11 +796,17 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
}
@Override
@Cacheable(key = "#p0")
public ImConversationQueryVo getImConversationById(Long id) {
return imConversationMapper.getImConversationById(id);
}
@Override
@CacheEvict(key = "#p0")
public void deleteCacheImConversationById(Long id) {
}
@Override
public Paging<ImConversationQueryVo> getImConversationPageList(ImConversationPageParam imConversationPageParam) throws Exception {
Page<ImConversationQueryVo> page = new PageInfo<>(imConversationPageParam, OrderItem.desc(getLambdaColumn(ImConversation::getCreateTime)));
IPage<ImConversationQueryVo> iPage = imConversationMapper.getImConversationPageList(page, imConversationPageParam);
......
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