Skip to content

Commit

Permalink
Add new property for clickhouse cache enabling (#11109)
Browse files Browse the repository at this point in the history
* add separate property for clickhouse cache enabling


---------

Co-authored-by: Bryan Lai <[email protected]>
Co-authored-by: alisman <[email protected]>
  • Loading branch information
3 people authored Oct 23, 2024
1 parent 7cd50ec commit 007de21
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 28 deletions.
17 changes: 17 additions & 0 deletions src/main/java/org/cbioportal/persistence/CacheEnabledConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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) {
Expand All @@ -53,4 +58,16 @@ public boolean isEnabled() {
return enabled;
}

public String getEnabledClickhouse() {
if (enabledClickhouse) {
return "true";
} else {
return "false";
}
}

public boolean isEnabledClickhouse() {
return enabledClickhouse;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class ClinicalDataDensityPlotServiceImpl implements ClinicalDataDensityPl

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabled()"
condition = "@cacheEnabledConfig.getEnabledClickhouse()"
)
@Override
public DensityPlotData getDensityPlotData(List<ClinicalData> sampleClinicalData, DensityPlotParameters densityPlotParameters) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Sample> getFilteredSamples(StudyViewFilter studyViewFilter) {
Expand All @@ -65,7 +65,7 @@ public List<Sample> getFilteredSamples(StudyViewFilter studyViewFilter) {

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabled()"
condition = "@cacheEnabledConfig.getEnabledClickhouse()"
)
@Override
public List<AlterationCountByGene> getMutatedGenes(StudyViewFilter studyViewFilter) throws StudyNotFoundException {
Expand All @@ -74,7 +74,7 @@ public List<AlterationCountByGene> getMutatedGenes(StudyViewFilter studyViewFilt

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabled()"
condition = "@cacheEnabledConfig.getEnabledClickhouse()"
)
@Override
public List<GenomicDataCount> getMolecularProfileSampleCounts(StudyViewFilter studyViewFilter) {
Expand All @@ -83,7 +83,7 @@ public List<GenomicDataCount> getMolecularProfileSampleCounts(StudyViewFilter st

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabled()"
condition = "@cacheEnabledConfig.getEnabledClickhouse()"
)
@Override
public List<ClinicalEventTypeCount> getClinicalEventTypeCounts(StudyViewFilter studyViewFilter) {
Expand All @@ -92,7 +92,7 @@ public List<ClinicalEventTypeCount> getClinicalEventTypeCounts(StudyViewFilter s

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabled()"
condition = "@cacheEnabledConfig.getEnabledClickhouse()"
)
@Override
public PatientTreatmentReport getPatientTreatmentReport(StudyViewFilter studyViewFilter) {
Expand All @@ -101,7 +101,7 @@ public PatientTreatmentReport getPatientTreatmentReport(StudyViewFilter studyVie

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabled()"
condition = "@cacheEnabledConfig.getEnabledClickhouse()"
)
@Override
public SampleTreatmentReport getSampleTreatmentReport(StudyViewFilter studyViewFilter) {
Expand All @@ -110,7 +110,7 @@ public SampleTreatmentReport getSampleTreatmentReport(StudyViewFilter studyViewF

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabled()"
condition = "@cacheEnabledConfig.getEnabledClickhouse()"
)
@Override
public List<ClinicalDataCountItem> getGenomicDataBinCounts(StudyViewFilter studyViewFilter, List<GenomicDataBinFilter> genomicDataBinFilters) {
Expand All @@ -119,7 +119,7 @@ public List<ClinicalDataCountItem> getGenomicDataBinCounts(StudyViewFilter study

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabled()"
condition = "@cacheEnabledConfig.getEnabledClickhouse()"
)
@Override
public List<ClinicalDataCountItem> getGenericAssayDataBinCounts(StudyViewFilter studyViewFilter, List<GenericAssayDataBinFilter> genericAssayDataBinFilters) {
Expand All @@ -132,7 +132,7 @@ public List<CopyNumberCountByGene> getCnaGenes(StudyViewFilter studyViewFilter)

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabled()"
condition = "@cacheEnabledConfig.getEnabledClickhouse()"
)
@Override
public List<AlterationCountByGene> getStructuralVariantGenes(StudyViewFilter studyViewFilter) throws StudyNotFoundException {
Expand All @@ -141,7 +141,7 @@ public List<AlterationCountByGene> getStructuralVariantGenes(StudyViewFilter stu

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabled()"
condition = "@cacheEnabledConfig.getEnabledClickhouse()"
)
@Override
public Map<String, ClinicalDataType> getClinicalAttributeDatatypeMap() {
Expand All @@ -150,7 +150,7 @@ public Map<String, ClinicalDataType> getClinicalAttributeDatatypeMap() {

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabled()"
condition = "@cacheEnabledConfig.getEnabledClickhouse()"
)
@Override
public List<ClinicalDataCountItem> getClinicalDataCounts(StudyViewFilter studyViewFilter, List<String> filteredAttributes) {
Expand All @@ -169,7 +169,7 @@ public List<ClinicalDataCountItem> getClinicalDataCounts(StudyViewFilter studyVi

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabled()"
condition = "@cacheEnabledConfig.getEnabledClickhouse()"
)
@Override
public List<CaseListDataCount> getCaseListDataCounts(StudyViewFilter studyViewFilter) {
Expand All @@ -181,7 +181,7 @@ public List<CaseListDataCount> getCaseListDataCounts(StudyViewFilter studyViewFi

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabled()"
condition = "@cacheEnabledConfig.getEnabledClickhouse()"
)
@Override
public List<ClinicalData> getPatientClinicalData(StudyViewFilter studyViewFilter, List<String> attributeIds) {
Expand All @@ -190,7 +190,7 @@ public List<ClinicalData> getPatientClinicalData(StudyViewFilter studyViewFilter

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabled()"
condition = "@cacheEnabledConfig.getEnabledClickhouse()"
)
@Override
public List<ClinicalData> getSampleClinicalData(StudyViewFilter studyViewFilter, List<String> attributeIds) {
Expand All @@ -199,7 +199,7 @@ public List<ClinicalData> getSampleClinicalData(StudyViewFilter studyViewFilter,

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabled()"
condition = "@cacheEnabledConfig.getEnabledClickhouse()"
)
@Override
public List<GenomicDataCountItem> getCNACountsByGeneSpecific(StudyViewFilter studyViewFilter, List<GenomicDataFilter> genomicDataFilters) {
Expand All @@ -208,7 +208,7 @@ public List<GenomicDataCountItem> getCNACountsByGeneSpecific(StudyViewFilter stu

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabled()"
condition = "@cacheEnabledConfig.getEnabledClickhouse()"
)
@Override
public List<GenericAssayDataCountItem> getGenericAssayDataCounts(StudyViewFilter studyViewFilter, List<GenericAssayDataFilter> genericAssayDataFilters) {
Expand All @@ -217,7 +217,7 @@ public List<GenericAssayDataCountItem> getGenericAssayDataCounts(StudyViewFilter

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabled()"
condition = "@cacheEnabledConfig.getEnabledClickhouse()"
)
@Override
public List<GenomicDataCountItem> getMutationCountsByGeneSpecific(StudyViewFilter studyViewFilter, List<GenomicDataFilter> genomicDataFilters) {
Expand All @@ -238,7 +238,7 @@ public List<GenomicDataCountItem> getMutationCountsByGeneSpecific(StudyViewFilte

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabled()"
condition = "@cacheEnabledConfig.getEnabledClickhouse()"
)
@Override
public List<GenomicDataCountItem> getMutationTypeCountsByGeneSpecific(StudyViewFilter studyViewFilter, List<GenomicDataFilter> genomicDataFilters) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ViolinPlotServiceImpl implements ViolinPlotService {

@Cacheable(
cacheResolver = "staticRepositoryCacheOneResolver",
condition = "@cacheEnabledConfig.getEnabled()"
condition = "@cacheEnabledConfig.getEnabledClickhouse()"
)
public ClinicalViolinPlotData getClinicalViolinPlotData(
List<ClinicalData> sampleClinicalDataForViolinPlot,
Expand Down

0 comments on commit 007de21

Please sign in to comment.