/** * @param appName * @return prioritized list of experiments for given application. */ @Override public Optional<PrioritizedExperimentList> getPrioritizedExperimentListMap(Application.Name appName) { PrioritizedExperimentList expList = null; Cache cache = cacheManager.getCache(APP_NAME_TO_PRIORITIZED_EXPERIMENTS_CACHE.toString()); Element val = cache.get(appName); if (isNull(val)) { expList = prioritiesRepository.getPriorities(singleEntrySet(appName)).get(appName); cache.put(new Element(appName, expList)); } else { expList = (PrioritizedExperimentList) val.getObjectValue(); } return Optional.ofNullable(expList); }
/** * {@inheritDoc} */ @Override public PrioritizedExperimentList getPriorities(Application.Name applicationName, boolean verifyPriorityList) { if (verifyPriorityList) { List<Experiment.ID> priorityList = prioritiesRepository.getPriorityList(applicationName); List<Experiment> experimentList = experiments.getExperiments(applicationName); if ((priorityList != null ? priorityList.size() : 0) != experimentList.size()) { prioritiesRepository.createPriorities(applicationName, cleanPriorityList(applicationName, priorityList)); } } return prioritiesRepository.getPriorities(applicationName); }
/** * 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; }