You've already forked DataMate
fix: 修复 cacheManager bean 冲突问题
- 重命名 cacheManager bean 为 knowledgeGraphCacheManager 和 dataManagementCacheManager - 更新所有引用处(@Cacheable、@Qualifier 注解) - 添加 @Primary 注解到 knowledgeGraphCacheManager 避免多 bean 冲突 - 修复文件: - DataManagementConfig.java - RedisCacheConfig.java - GraphEntityService.java - GraphQueryService.java - GraphCacheService.java - CacheableIntegrationTest.java
This commit is contained in:
@@ -21,8 +21,8 @@ public class DataManagementConfig {
|
||||
/**
|
||||
* 缓存管理器
|
||||
*/
|
||||
@Bean
|
||||
public CacheManager cacheManager() {
|
||||
@Bean("dataManagementCacheManager")
|
||||
public CacheManager dataManagementCacheManager() {
|
||||
return new ConcurrentMapCacheManager("datasets", "datasetFiles", "tags");
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,8 @@ public class GraphEntityService {
|
||||
|
||||
@Cacheable(value = RedisCacheConfig.CACHE_ENTITIES,
|
||||
key = "T(com.datamate.knowledgegraph.infrastructure.cache.GraphCacheService).cacheKey(#graphId, #entityId)",
|
||||
unless = "#result == null")
|
||||
unless = "#result == null",
|
||||
cacheManager = "knowledgeGraphCacheManager")
|
||||
public GraphEntity getEntity(String graphId, String entityId) {
|
||||
validateGraphId(graphId);
|
||||
return entityRepository.findByIdAndGraphId(entityId, graphId)
|
||||
@@ -71,7 +72,8 @@ public class GraphEntityService {
|
||||
}
|
||||
|
||||
@Cacheable(value = RedisCacheConfig.CACHE_ENTITIES,
|
||||
key = "T(com.datamate.knowledgegraph.infrastructure.cache.GraphCacheService).cacheKey(#graphId, 'list')")
|
||||
key = "T(com.datamate.knowledgegraph.infrastructure.cache.GraphCacheService).cacheKey(#graphId, 'list')",
|
||||
cacheManager = "knowledgeGraphCacheManager")
|
||||
public List<GraphEntity> listEntities(String graphId) {
|
||||
validateGraphId(graphId);
|
||||
return entityRepository.findByGraphId(graphId);
|
||||
|
||||
@@ -73,7 +73,8 @@ public class GraphQueryService {
|
||||
* @param limit 返回节点数上限
|
||||
*/
|
||||
@Cacheable(value = RedisCacheConfig.CACHE_QUERIES,
|
||||
key = "T(com.datamate.knowledgegraph.infrastructure.cache.GraphCacheService).cacheKey(#graphId, #entityId, #depth, #limit, @resourceAccessService.resolveOwnerFilterUserId(), @resourceAccessService.canViewConfidential())")
|
||||
key = "T(com.datamate.knowledgegraph.infrastructure.cache.GraphCacheService).cacheKey(#graphId, #entityId, #depth, #limit, @resourceAccessService.resolveOwnerFilterUserId(), @resourceAccessService.canViewConfidential())",
|
||||
cacheManager = "knowledgeGraphCacheManager")
|
||||
public SubgraphVO getNeighborGraph(String graphId, String entityId, int depth, int limit) {
|
||||
validateGraphId(graphId);
|
||||
String filterUserId = resolveOwnerFilter();
|
||||
@@ -573,7 +574,8 @@ public class GraphQueryService {
|
||||
* @param query 搜索关键词(支持 Lucene 查询语法)
|
||||
*/
|
||||
@Cacheable(value = RedisCacheConfig.CACHE_SEARCH,
|
||||
key = "T(com.datamate.knowledgegraph.infrastructure.cache.GraphCacheService).cacheKey(#graphId, #query, #page, #size, @resourceAccessService.resolveOwnerFilterUserId(), @resourceAccessService.canViewConfidential())")
|
||||
key = "T(com.datamate.knowledgegraph.infrastructure.cache.GraphCacheService).cacheKey(#graphId, #query, #page, #size, @resourceAccessService.resolveOwnerFilterUserId(), @resourceAccessService.canViewConfidential())",
|
||||
cacheManager = "knowledgeGraphCacheManager")
|
||||
public PagedResponse<SearchHitVO> fulltextSearch(String graphId, String query, int page, int size) {
|
||||
validateGraphId(graphId);
|
||||
String filterUserId = resolveOwnerFilter();
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.datamate.knowledgegraph.infrastructure.cache;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.cache.Cache;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
@@ -28,7 +29,7 @@ public class GraphCacheService {
|
||||
private final CacheManager cacheManager;
|
||||
private StringRedisTemplate redisTemplate;
|
||||
|
||||
public GraphCacheService(CacheManager cacheManager) {
|
||||
public GraphCacheService(@Qualifier("knowledgeGraphCacheManager") CacheManager cacheManager) {
|
||||
this.cacheManager = cacheManager;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.data.redis.cache.RedisCacheConfiguration;
|
||||
import org.springframework.data.redis.cache.RedisCacheManager;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
@@ -43,8 +44,9 @@ public class RedisCacheConfig {
|
||||
/** 搜索缓存:全文搜索结果 */
|
||||
public static final String CACHE_SEARCH = "kg:search";
|
||||
|
||||
@Bean
|
||||
public CacheManager cacheManager(
|
||||
@Primary
|
||||
@Bean("knowledgeGraphCacheManager")
|
||||
public CacheManager knowledgeGraphCacheManager(
|
||||
RedisConnectionFactory connectionFactory,
|
||||
KnowledgeGraphProperties properties
|
||||
) {
|
||||
|
||||
@@ -47,8 +47,8 @@ class CacheableIntegrationTest {
|
||||
@EnableCaching
|
||||
static class Config {
|
||||
|
||||
@Bean
|
||||
CacheManager cacheManager() {
|
||||
@Bean("knowledgeGraphCacheManager")
|
||||
CacheManager knowledgeGraphCacheManager() {
|
||||
return new ConcurrentMapCacheManager(
|
||||
RedisCacheConfig.CACHE_ENTITIES,
|
||||
RedisCacheConfig.CACHE_QUERIES,
|
||||
|
||||
Reference in New Issue
Block a user