/*
 * Copyright 2008-2013 Microarray Informatics Team, EMBL-European Bioinformatics Institute
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *
 * For further details of the Gene Expression Atlas project, including source code,
 * downloads and documentation, please see:
 *
 * http://gxa.github.com/gxa
 */

package uk.ac.ebi.atlas.trader.cache;

import com.google.common.cache.CacheBuilder;
import com.google.common.cache.LoadingCache;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import uk.ac.ebi.atlas.model.baseline.BaselineExperiment;
import uk.ac.ebi.atlas.model.baseline.barcharts.BarChartTrader;
import uk.ac.ebi.atlas.trader.loader.BarChartTradersCacheLoader;
import uk.ac.ebi.atlas.trader.loader.BaselineExperimentsCacheLoader;
import uk.ac.ebi.atlas.trader.loader.DifferentialExperimentsCacheLoader;
import uk.ac.ebi.atlas.trader.loader.MicroarrayExperimentsCacheLoader;
import uk.ac.ebi.atlas.model.differential.DifferentialExperiment;
import uk.ac.ebi.atlas.model.differential.microarray.MicroarrayExperiment;

import javax.inject.Inject;

@Configuration
public class CacheConfiguration {

    private static final int EXPERIMENTS_CACHE_MAX_SIZE = 500;

    @Bean(name="baselineExperimentsLoadingCache")
    @Inject
    public LoadingCache<String, BaselineExperiment> baselineExperimentsCache(BaselineExperimentsCacheLoader cacheLoader){

        return CacheBuilder.newBuilder().maximumSize(EXPERIMENTS_CACHE_MAX_SIZE).build(cacheLoader);

    }


    @Bean(name="differentialExperimentsLoadingCache")
    @Inject
    public LoadingCache<String, DifferentialExperiment> differentialExperimentsCache(DifferentialExperimentsCacheLoader cacheLoader){

        return CacheBuilder.newBuilder().maximumSize(EXPERIMENTS_CACHE_MAX_SIZE).build(cacheLoader);

    }

    @Bean(name="microarrayExperimentsLoadingCache")
    @Inject
    public LoadingCache<String, MicroarrayExperiment> microarrayExperimentsCache(MicroarrayExperimentsCacheLoader cacheLoader){

        return CacheBuilder.newBuilder().maximumSize(EXPERIMENTS_CACHE_MAX_SIZE).build(cacheLoader);

    }

    @Bean(name="barChartTradersLoadingCache")
    @Inject
    public LoadingCache<String, BarChartTrader> barChartTradersCache(BarChartTradersCacheLoader barChartTradersCacheLoader) {

        return CacheBuilder.newBuilder().maximumSize(EXPERIMENTS_CACHE_MAX_SIZE).build(barChartTradersCacheLoader);

    }

}
@@ -1172,24 +1172,165 @@
 hartTrader;%0A
+import uk.ac.ebi.atlas.model.differential.DifferentialExperiment;%0Aimport uk.ac.ebi.atlas.model.differential.microarray.MicroarrayExperiment;%0A
 import uk.ac
@@ -1598,149 +1598,8 @@
 der;
-%0Aimport uk.ac.ebi.atlas.model.differential.DifferentialExperiment;%0Aimport uk.ac.ebi.atlas.model.differential.microarray.MicroarrayExperiment;
 %0A%0Aim
@@ -1704,16 +1704,25 @@
 nal int 
+BASELINE_
 EXPERIME
@@ -1744,16 +1744,165 @@
 IZE = 50
+;%0A    private static final int RNASEQ_DIFF_EXPERIMENTS_CACHE_MAX_SIZE = 100;%0A    private static final int MICROARRAY_EXPERIMENTS_CACHE_MAX_SIZE = 200
 0;%0A%0A    
@@ -2127,32 +2127,41 @@
 r().maximumSize(
+BASELINE_
 EXPERIMENTS_CACH
@@ -2447,32 +2447,44 @@
 r().maximumSize(
+RNASEQ_DIFF_
 EXPERIMENTS_CACH
@@ -2761,32 +2761,43 @@
 r().maximumSize(
+MICROARRAY_
 EXPERIMENTS_CACH
@@ -3074,16 +3074,25 @@
 mumSize(
+BASELINE_
 EXPERIME

increase experiments cache size: we now have 13 baseline, 528 microarray, and 24 rnaseq differential experiments. So increase cache size appropriately.