org.eclipse.xpanse.modules.cache.CaffeineCacheConfig Maven / Gradle / Ivy
The newest version!
/*
* SPDX-License-Identifier: Apache-2.0
* SPDX-FileCopyrightText: Huawei Inc.
*
*/
package org.eclipse.xpanse.modules.cache;
import static org.eclipse.xpanse.modules.cache.consts.CacheConstants.CREDENTIAL_CACHE_NAME;
import static org.eclipse.xpanse.modules.cache.consts.CacheConstants.DEFAULT_CACHE_EXPIRE_TIME_IN_MINUTES;
import static org.eclipse.xpanse.modules.cache.consts.CacheConstants.DEPLOYER_VERSIONS_CACHE_NAME;
import static org.eclipse.xpanse.modules.cache.consts.CacheConstants.MONITOR_METRICS_CACHE_NAME;
import static org.eclipse.xpanse.modules.cache.consts.CacheConstants.REGION_AZS_CACHE_NAME;
import static org.eclipse.xpanse.modules.cache.consts.CacheConstants.SERVICE_FLAVOR_PRICE_CACHE_NAME;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.RemovalCause;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.xpanse.modules.cache.credential.CredentialCacheKey;
import org.eclipse.xpanse.modules.cache.credential.CredentialCaffeineCacheExpiry;
import org.eclipse.xpanse.modules.cache.monitor.MonitorMetricsCacheKey;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.CacheManager;
import org.springframework.cache.caffeine.CaffeineCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* Caffeine cache configuration class.
*/
@Slf4j
@Configuration
public class CaffeineCacheConfig {
@Value("${region.azs.cache.expire.time.in.minutes:60}")
private long regionAzsCacheDuration;
@Value("${service.flavor.price.cache.expire.time.in.minutes:60}")
private long flavorPriceCacheDuration;
@Value("${service.monitor.metrics.cache.expire.time.in.minutes:60}")
private long monitorMetricsCacheDuration;
/**
* Config cache manager with caffeine.
*
* @return caffeineCacheManager
*/
@Bean
public CacheManager caffeineCacheManager() {
CaffeineCacheManager cacheManager = new CaffeineCacheManager();
cacheManager.registerCustomCache(REGION_AZS_CACHE_NAME, getRegionAzsCache());
cacheManager.registerCustomCache(SERVICE_FLAVOR_PRICE_CACHE_NAME,
getServiceFlavorPriceCache());
cacheManager.registerCustomCache(CREDENTIAL_CACHE_NAME, getCredentialsCache());
cacheManager.registerCustomCache(MONITOR_METRICS_CACHE_NAME, getMonitorMetricsCache());
cacheManager.registerCustomCache(DEPLOYER_VERSIONS_CACHE_NAME, getDeployerVersionsCache());
return cacheManager;
}
private Cache
© 2015 - 2025 Weber Informatics LLC | Privacy Policy