mirror of
https://gitee.com/dromara/MaxKey.git
synced 2026-06-11 16:16:53 +08:00
fix: 修复机构配置修改后缓存没有清空,导致界面上看上去 修改失败了
This commit is contained in:
@@ -23,7 +23,13 @@ import org.dromara.mybatis.jpa.service.IJpaService;
|
||||
public interface InstitutionsService extends IJpaService<Institutions>{
|
||||
|
||||
public Institutions findByDomain(String domain) ;
|
||||
|
||||
|
||||
|
||||
|
||||
public Institutions get(String instIdOrDomain) ;
|
||||
|
||||
/**
|
||||
* 清除指定机构的缓存
|
||||
* @param instIdOrDomain 机构ID或域名
|
||||
*/
|
||||
void clearInstitutionsCache(String instIdOrDomain);
|
||||
}
|
||||
|
||||
@@ -71,5 +71,30 @@ public class InstitutionsServiceImpl extends JpaServiceImpl<InstitutionsMapper,
|
||||
|
||||
return inst;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void clearInstitutionsCache(String instIdOrDomain) {
|
||||
_logger.debug("clearInstitutionsCache instIdOrDomain: {}", instIdOrDomain);
|
||||
|
||||
// 先尝试从缓存中获取
|
||||
Institutions inst = institutionsStore.getIfPresent(instIdOrDomain);
|
||||
|
||||
// 如果缓存中没有,从数据库查询
|
||||
if(inst == null) {
|
||||
inst = findByDomain(instIdOrDomain);
|
||||
}
|
||||
|
||||
// 清除所有相关的缓存key
|
||||
if(inst != null) {
|
||||
institutionsStore.invalidate(inst.getDomain());
|
||||
institutionsStore.invalidate(inst.getConsoleDomain());
|
||||
institutionsStore.invalidate(inst.getId());
|
||||
_logger.debug("Cleared cache for domain: {}, consoleDomain: {}, id: {}",
|
||||
inst.getDomain(), inst.getConsoleDomain(), inst.getId());
|
||||
}
|
||||
|
||||
// 同时清除传入的key(可能是别名或其他key)
|
||||
institutionsStore.invalidate(instIdOrDomain);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -52,6 +52,9 @@ public class InstitutionsController {
|
||||
BindingResult result) {
|
||||
logger.debug("updateRole institutions : {}" , institutions);
|
||||
if(institutionsService.update(institutions)) {
|
||||
// 更新成功后清除缓存
|
||||
institutionsService.clearInstitutionsCache(institutions.getId());
|
||||
logger.debug("Cleared institutions cache for id: {}", institutions.getId());
|
||||
return new Message<Institutions>(Message.SUCCESS);
|
||||
} else {
|
||||
return new Message<Institutions>(Message.FAIL);
|
||||
|
||||
Reference in New Issue
Block a user