diff --git a/src/main/java/org/cbioportal/persistence/CacheEnabledConfig.java b/src/main/java/org/cbioportal/persistence/CacheEnabledConfig.java index af04bac392c..45b22f5bbf4 100644 --- a/src/main/java/org/cbioportal/persistence/CacheEnabledConfig.java +++ b/src/main/java/org/cbioportal/persistence/CacheEnabledConfig.java @@ -16,8 +16,11 @@ public class CacheEnabledConfig { @Value("${persistence.cache_type:no-cache}") private String cacheType; + @Value("${persistence.cache_type_clickhouse:no-cache}") + private String cacheTypeClickhouse; private boolean enabled; + private boolean enabledClickhouse; public static final String EHCACHE_DISK = "ehcache-disk"; public static final String EHCACHE_HEAP = "ehcache-heap"; @@ -30,6 +33,8 @@ public class CacheEnabledConfig { public void init() { this.enabled = enableCache(cacheType); LOG.info("Cache is enabled: " + this.enabled); + this.enabledClickhouse = enableCache(cacheTypeClickhouse); + LOG.info("Cache is enabled for clickhouse: " + this.enabledClickhouse); } public static boolean enableCache(String cacheType) { @@ -53,4 +58,16 @@ public boolean isEnabled() { return enabled; } + public String getEnabledClickhouse() { + if (enabledClickhouse) { + return "true"; + } else { + return "false"; + } + } + + public boolean isEnabledClickhouse() { + return enabledClickhouse; + } + } diff --git a/src/main/java/org/cbioportal/persistence/cachemaputil/SpringManagedCacheMapUtil.java b/src/main/java/org/cbioportal/persistence/cachemaputil/SpringManagedCacheMapUtil.java index e58f04b6cf5..c492b2400b0 100644 --- a/src/main/java/org/cbioportal/persistence/cachemaputil/SpringManagedCacheMapUtil.java +++ b/src/main/java/org/cbioportal/persistence/cachemaputil/SpringManagedCacheMapUtil.java @@ -57,6 +57,8 @@ public class SpringManagedCacheMapUtil implements CacheMapUtil { @Value("${persistence.cache_type:no-cache}") private String cacheType; + @Value("${persistence.cache_type_clickhouse:no-cache}") + private String cacheTypeClickhouse; @Value("${cache.cache-map-utils.spring-managed}") private boolean springManagedCacheMapUtils; @@ -67,7 +69,7 @@ public class SpringManagedCacheMapUtil implements CacheMapUtil { @PostConstruct public void init() { // Make sure the user does not have a conflicting configuration. Explode if there is. - if (cacheType.equals("no-cache") && springManagedCacheMapUtils) { + if (cacheType.equals("no-cache") && cacheTypeClickhouse.equals("no-cache") && springManagedCacheMapUtils) { throw new RuntimeException("cache.cache-map-utils.spring-managed property is set to 'true' but the portal is not " + "configured with a cache-implementation (persistence.cache_type property is 'no-cache'). Please set to 'false'" + " or configure the cache."); diff --git a/src/main/java/org/cbioportal/persistence/config/RedisConfig.java b/src/main/java/org/cbioportal/persistence/config/RedisConfig.java index 2da81e8787c..99c225a33bd 100644 --- a/src/main/java/org/cbioportal/persistence/config/RedisConfig.java +++ b/src/main/java/org/cbioportal/persistence/config/RedisConfig.java @@ -3,8 +3,8 @@ import org.cbioportal.persistence.util.CustomKeyGenerator; import org.cbioportal.persistence.util.CustomRedisCachingProvider; import org.cbioportal.persistence.util.LoggingCacheErrorHandler; -import org.cbioportal.utils.config.annotation.ConditionalOnProperty; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.cache.CacheManager; import org.springframework.cache.annotation.CachingConfigurerSupport; import org.springframework.cache.annotation.EnableCaching; @@ -18,7 +18,9 @@ @Configuration @EnableCaching -@ConditionalOnProperty(name = "persistence.cache_type", havingValue = {"redis"}) +@ConditionalOnExpression( + "#{environment['persistence.cache_type'] == 'redis' or environment['persistence.cache_type_clickhouse'] == 'redis'}" +) public class RedisConfig extends CachingConfigurerSupport { @Value("${redis.name:cbioportal}") diff --git a/src/main/java/org/cbioportal/persistence/util/CustomKeyGenerator.java b/src/main/java/org/cbioportal/persistence/util/CustomKeyGenerator.java index 1ae254cef05..948d5d344c5 100644 --- a/src/main/java/org/cbioportal/persistence/util/CustomKeyGenerator.java +++ b/src/main/java/org/cbioportal/persistence/util/CustomKeyGenerator.java @@ -64,7 +64,7 @@ public class CustomKeyGenerator implements KeyGenerator { private static final Logger LOG = LoggerFactory.getLogger(CustomKeyGenerator.class); public Object generate(Object target, Method method, Object... params) { - if (!cacheEnabledConfig.isEnabled()) { + if (!cacheEnabledConfig.isEnabled() && !cacheEnabledConfig.isEnabledClickhouse()) { return ""; } String key = target.getClass().getSimpleName() + CACHE_KEY_PARAM_DELIMITER diff --git a/src/main/java/org/cbioportal/persistence/util/RedisCacheUtils.java b/src/main/java/org/cbioportal/persistence/util/RedisCacheUtils.java index 67639dc75b5..ec5579c544d 100644 --- a/src/main/java/org/cbioportal/persistence/util/RedisCacheUtils.java +++ b/src/main/java/org/cbioportal/persistence/util/RedisCacheUtils.java @@ -3,9 +3,9 @@ import static org.cbioportal.persistence.util.CustomRedisCache.DELIMITER; -import org.cbioportal.utils.config.annotation.ConditionalOnProperty; import org.redisson.api.RedissonClient; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.cache.Cache; import org.springframework.cache.CacheManager; import org.springframework.stereotype.Component; @@ -14,7 +14,9 @@ import java.util.stream.Collectors; @Component -@ConditionalOnProperty(name = "persistence.cache_type", havingValue = "redis") +@ConditionalOnExpression( + "#{environment['persistence.cache_type'] == 'redis' or environment['persistence.cache_type_clickhouse'] == 'redis'}" +) public class RedisCacheUtils implements CacheUtils { @Autowired diff --git a/src/main/java/org/cbioportal/service/impl/ClinicalDataDensityPlotServiceImpl.java b/src/main/java/org/cbioportal/service/impl/ClinicalDataDensityPlotServiceImpl.java index 0883ff6491f..b6e4a55e679 100644 --- a/src/main/java/org/cbioportal/service/impl/ClinicalDataDensityPlotServiceImpl.java +++ b/src/main/java/org/cbioportal/service/impl/ClinicalDataDensityPlotServiceImpl.java @@ -25,7 +25,7 @@ public class ClinicalDataDensityPlotServiceImpl implements ClinicalDataDensityPl @Cacheable( cacheResolver = "staticRepositoryCacheOneResolver", - condition = "@cacheEnabledConfig.getEnabled()" + condition = "@cacheEnabledConfig.getEnabledClickhouse()" ) @Override public DensityPlotData getDensityPlotData(List sampleClinicalData, DensityPlotParameters densityPlotParameters) { diff --git a/src/main/java/org/cbioportal/service/impl/RedisCacheStatisticsServiceImpl.java b/src/main/java/org/cbioportal/service/impl/RedisCacheStatisticsServiceImpl.java index e6abafc1cc5..ef8e447355a 100644 --- a/src/main/java/org/cbioportal/service/impl/RedisCacheStatisticsServiceImpl.java +++ b/src/main/java/org/cbioportal/service/impl/RedisCacheStatisticsServiceImpl.java @@ -7,6 +7,7 @@ import org.cbioportal.utils.config.annotation.ConditionalOnProperty; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.cache.Cache; import org.springframework.cache.CacheManager; import org.springframework.security.access.AccessDeniedException; @@ -19,7 +20,9 @@ import java.util.stream.Collectors; @Service -@ConditionalOnProperty(name = "persistence.cache_type", havingValue = {"redis"}) +@ConditionalOnExpression( + "#{environment['persistence.cache_type'] == 'redis' or environment['persistence.cache_type_clickhouse'] == 'redis'}" +) public class RedisCacheStatisticsServiceImpl implements CacheStatisticsService { @Autowired diff --git a/src/main/java/org/cbioportal/service/impl/StudyViewColumnarServiceImpl.java b/src/main/java/org/cbioportal/service/impl/StudyViewColumnarServiceImpl.java index 8a4ca8ccdfd..26e988f73cb 100644 --- a/src/main/java/org/cbioportal/service/impl/StudyViewColumnarServiceImpl.java +++ b/src/main/java/org/cbioportal/service/impl/StudyViewColumnarServiceImpl.java @@ -52,10 +52,10 @@ public StudyViewColumnarServiceImpl(StudyViewRepository studyViewRepository, Alt this.customDataFilterUtil = customDataFilterUtil; } - // should condition = "@cacheEnabledConfig.getEnabled() && #singleStudyUnfiltered" + // should condition = "@cacheEnabledConfig.getEnabledClickhouse() && #singleStudyUnfiltered" @Cacheable( cacheResolver = "staticRepositoryCacheOneResolver", - condition = "@cacheEnabledConfig.getEnabled()" + condition = "@cacheEnabledConfig.getEnabledClickhouse()" ) @Override public List getFilteredSamples(StudyViewFilter studyViewFilter) { @@ -65,7 +65,7 @@ public List getFilteredSamples(StudyViewFilter studyViewFilter) { @Cacheable( cacheResolver = "staticRepositoryCacheOneResolver", - condition = "@cacheEnabledConfig.getEnabled()" + condition = "@cacheEnabledConfig.getEnabledClickhouse()" ) @Override public List getMutatedGenes(StudyViewFilter studyViewFilter) throws StudyNotFoundException { @@ -74,7 +74,7 @@ public List getMutatedGenes(StudyViewFilter studyViewFilt @Cacheable( cacheResolver = "staticRepositoryCacheOneResolver", - condition = "@cacheEnabledConfig.getEnabled()" + condition = "@cacheEnabledConfig.getEnabledClickhouse()" ) @Override public List getMolecularProfileSampleCounts(StudyViewFilter studyViewFilter) { @@ -83,7 +83,7 @@ public List getMolecularProfileSampleCounts(StudyViewFilter st @Cacheable( cacheResolver = "staticRepositoryCacheOneResolver", - condition = "@cacheEnabledConfig.getEnabled()" + condition = "@cacheEnabledConfig.getEnabledClickhouse()" ) @Override public List getClinicalEventTypeCounts(StudyViewFilter studyViewFilter) { @@ -92,7 +92,7 @@ public List getClinicalEventTypeCounts(StudyViewFilter s @Cacheable( cacheResolver = "staticRepositoryCacheOneResolver", - condition = "@cacheEnabledConfig.getEnabled()" + condition = "@cacheEnabledConfig.getEnabledClickhouse()" ) @Override public PatientTreatmentReport getPatientTreatmentReport(StudyViewFilter studyViewFilter) { @@ -101,7 +101,7 @@ public PatientTreatmentReport getPatientTreatmentReport(StudyViewFilter studyVie @Cacheable( cacheResolver = "staticRepositoryCacheOneResolver", - condition = "@cacheEnabledConfig.getEnabled()" + condition = "@cacheEnabledConfig.getEnabledClickhouse()" ) @Override public SampleTreatmentReport getSampleTreatmentReport(StudyViewFilter studyViewFilter) { @@ -110,7 +110,7 @@ public SampleTreatmentReport getSampleTreatmentReport(StudyViewFilter studyViewF @Cacheable( cacheResolver = "staticRepositoryCacheOneResolver", - condition = "@cacheEnabledConfig.getEnabled()" + condition = "@cacheEnabledConfig.getEnabledClickhouse()" ) @Override public List getGenomicDataBinCounts(StudyViewFilter studyViewFilter, List genomicDataBinFilters) { @@ -119,7 +119,7 @@ public List getGenomicDataBinCounts(StudyViewFilter study @Cacheable( cacheResolver = "staticRepositoryCacheOneResolver", - condition = "@cacheEnabledConfig.getEnabled()" + condition = "@cacheEnabledConfig.getEnabledClickhouse()" ) @Override public List getGenericAssayDataBinCounts(StudyViewFilter studyViewFilter, List genericAssayDataBinFilters) { @@ -132,7 +132,7 @@ public List getCnaGenes(StudyViewFilter studyViewFilter) @Cacheable( cacheResolver = "staticRepositoryCacheOneResolver", - condition = "@cacheEnabledConfig.getEnabled()" + condition = "@cacheEnabledConfig.getEnabledClickhouse()" ) @Override public List getStructuralVariantGenes(StudyViewFilter studyViewFilter) throws StudyNotFoundException { @@ -141,7 +141,7 @@ public List getStructuralVariantGenes(StudyViewFilter stu @Cacheable( cacheResolver = "staticRepositoryCacheOneResolver", - condition = "@cacheEnabledConfig.getEnabled()" + condition = "@cacheEnabledConfig.getEnabledClickhouse()" ) @Override public Map getClinicalAttributeDatatypeMap() { @@ -150,7 +150,7 @@ public Map getClinicalAttributeDatatypeMap() { @Cacheable( cacheResolver = "staticRepositoryCacheOneResolver", - condition = "@cacheEnabledConfig.getEnabled()" + condition = "@cacheEnabledConfig.getEnabledClickhouse()" ) @Override public List getClinicalDataCounts(StudyViewFilter studyViewFilter, List filteredAttributes) { @@ -169,7 +169,7 @@ public List getClinicalDataCounts(StudyViewFilter studyVi @Cacheable( cacheResolver = "staticRepositoryCacheOneResolver", - condition = "@cacheEnabledConfig.getEnabled()" + condition = "@cacheEnabledConfig.getEnabledClickhouse()" ) @Override public List getCaseListDataCounts(StudyViewFilter studyViewFilter) { @@ -181,7 +181,7 @@ public List getCaseListDataCounts(StudyViewFilter studyViewFi @Cacheable( cacheResolver = "staticRepositoryCacheOneResolver", - condition = "@cacheEnabledConfig.getEnabled()" + condition = "@cacheEnabledConfig.getEnabledClickhouse()" ) @Override public List getPatientClinicalData(StudyViewFilter studyViewFilter, List attributeIds) { @@ -190,7 +190,7 @@ public List getPatientClinicalData(StudyViewFilter studyViewFilter @Cacheable( cacheResolver = "staticRepositoryCacheOneResolver", - condition = "@cacheEnabledConfig.getEnabled()" + condition = "@cacheEnabledConfig.getEnabledClickhouse()" ) @Override public List getSampleClinicalData(StudyViewFilter studyViewFilter, List attributeIds) { @@ -199,7 +199,7 @@ public List getSampleClinicalData(StudyViewFilter studyViewFilter, @Cacheable( cacheResolver = "staticRepositoryCacheOneResolver", - condition = "@cacheEnabledConfig.getEnabled()" + condition = "@cacheEnabledConfig.getEnabledClickhouse()" ) @Override public List getCNACountsByGeneSpecific(StudyViewFilter studyViewFilter, List genomicDataFilters) { @@ -208,7 +208,7 @@ public List getCNACountsByGeneSpecific(StudyViewFilter stu @Cacheable( cacheResolver = "staticRepositoryCacheOneResolver", - condition = "@cacheEnabledConfig.getEnabled()" + condition = "@cacheEnabledConfig.getEnabledClickhouse()" ) @Override public List getGenericAssayDataCounts(StudyViewFilter studyViewFilter, List genericAssayDataFilters) { @@ -217,7 +217,7 @@ public List getGenericAssayDataCounts(StudyViewFilter @Cacheable( cacheResolver = "staticRepositoryCacheOneResolver", - condition = "@cacheEnabledConfig.getEnabled()" + condition = "@cacheEnabledConfig.getEnabledClickhouse()" ) @Override public List getMutationCountsByGeneSpecific(StudyViewFilter studyViewFilter, List genomicDataFilters) { @@ -238,7 +238,7 @@ public List getMutationCountsByGeneSpecific(StudyViewFilte @Cacheable( cacheResolver = "staticRepositoryCacheOneResolver", - condition = "@cacheEnabledConfig.getEnabled()" + condition = "@cacheEnabledConfig.getEnabledClickhouse()" ) @Override public List getMutationTypeCountsByGeneSpecific(StudyViewFilter studyViewFilter, List genomicDataFilters) { diff --git a/src/main/java/org/cbioportal/service/impl/ViolinPlotServiceImpl.java b/src/main/java/org/cbioportal/service/impl/ViolinPlotServiceImpl.java index 5675b855388..53e7f620874 100644 --- a/src/main/java/org/cbioportal/service/impl/ViolinPlotServiceImpl.java +++ b/src/main/java/org/cbioportal/service/impl/ViolinPlotServiceImpl.java @@ -20,7 +20,7 @@ public class ViolinPlotServiceImpl implements ViolinPlotService { @Cacheable( cacheResolver = "staticRepositoryCacheOneResolver", - condition = "@cacheEnabledConfig.getEnabled()" + condition = "@cacheEnabledConfig.getEnabledClickhouse()" ) public ClinicalViolinPlotData getClinicalViolinPlotData( List sampleClinicalDataForViolinPlot,