/** * @param appName * @return List of experiments created in the given application. */ @Override public List<Experiment> getExperimentsByAppName(Application.Name appName) { List<Experiment> expList = null; Cache cache = cacheManager.getCache(APP_NAME_TO_EXPERIMENTS_CACHE.toString()); Element val = cache.get(appName); if (isNull(val)) { expList = experimentRepository.getExperimentsForApps(singleEntrySet(appName)).get(appName); cache.put(new Element(appName, expList)); } else { expList = (List<Experiment>) val.getObjectValue(); } return isNull(expList) ? new ArrayList<>() : expList; }
/** * This method refresh the existing cache (keys) with the updated data from Database. * <p> * This method doesn't add new keys into the cache. * * @return TRUE if cache is successfully refreshed else FALSE. */ @Override public boolean refresh() { //------------------------------------------------------------------------------------------------ //Get updated data from database for each caches //------------------------------------------------------------------------------------------------ List<Element> appToExperiments = makeElementsList(experimentRepository.getExperimentsForApps(keys(APP_NAME_TO_EXPERIMENTS_CACHE))); List<Element> expIdsToExperiments = makeElementsList(experimentRepository.getExperimentsMap(keys(EXPERIMENT_ID_TO_EXPERIMENT_CACHE))); List<Element> appToPrioritizedExperiments = makeElementsList(prioritiesRepository.getPriorities(keys(APP_NAME_TO_PRIORITIZED_EXPERIMENTS_CACHE))); List<Element> expIdsToExclusions = makeElementsList(mutexRepository.getExclusivesList(keys(EXPERIMENT_ID_TO_EXCLUSION_CACHE))); List<Element> expIdsToBuckets = makeElementsList(experimentRepository.getBucketList(keys(EXPERIMENT_ID_TO_BUCKET_CACHE))); List<Element> appNPageToExperiments = makeElementsList(pagesRepository.getExperimentsWithoutLabels(keys(APP_NAME_N_PAGE_TO_EXPERIMENTS_CACHE))); //------------------------------------------------------------------------------------------------ //Now update individual caches //------------------------------------------------------------------------------------------------ cacheManager.getCache(APP_NAME_TO_EXPERIMENTS_CACHE.toString()).putAll(appToExperiments); cacheManager.getCache(EXPERIMENT_ID_TO_EXPERIMENT_CACHE.toString()).putAll(expIdsToExperiments); cacheManager.getCache(APP_NAME_TO_PRIORITIZED_EXPERIMENTS_CACHE.toString()).putAll(appToPrioritizedExperiments); cacheManager.getCache(EXPERIMENT_ID_TO_EXCLUSION_CACHE.toString()).putAll(expIdsToExclusions); cacheManager.getCache(EXPERIMENT_ID_TO_BUCKET_CACHE.toString()).putAll(expIdsToBuckets); cacheManager.getCache(APP_NAME_N_PAGE_TO_EXPERIMENTS_CACHE.toString()).putAll(appNPageToExperiments); LOGGER.debug("Assignments metadata cache has been refreshed successfully..."); return Boolean.TRUE; }