org.springframework.cache.caffeine.CaffeineCacheManager Java Examples
The following examples show how to use
org.springframework.cache.caffeine.CaffeineCacheManager.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LoadBalancerCacheAutoConfigurationTests.java From spring-cloud-commons with Apache License 2.0 | 6 votes |
@Test void loadBalancerCacheShouldNotOverrideExistingCaffeineCacheManager() { ApplicationContextRunner contextRunner = baseApplicationRunner() .withUserConfiguration(TestConfiguration.class); contextRunner.run(context -> { assertThat(context.getBeansOfType(CacheManager.class)).hasSize(2); assertThat(context.getBean("cacheManager")) .isInstanceOf(CaffeineCacheManager.class); assertThat(((CacheManager) context.getBean("cacheManager")).getCacheNames()) .isEmpty(); assertThat( ((CacheManager) context.getBean("caffeineLoadBalancerCacheManager")) .getCacheNames()).hasSize(1); assertThat( ((CacheManager) context.getBean("caffeineLoadBalancerCacheManager")) .getCacheNames()) .contains("CachingServiceInstanceListSupplierCache"); }); }
Example #2
Source File: LoadBalancerCacheAutoConfigurationTests.java From spring-cloud-commons with Apache License 2.0 | 6 votes |
@Test void shouldAutoEnableCaching() { ApplicationContextRunner contextRunner = baseApplicationRunner(); contextRunner.run(context -> { assertThat(context.getBeansOfType(CacheManager.class)).hasSize(1); assertThat( ((CacheManager) context.getBean("caffeineLoadBalancerCacheManager")) .getCacheNames()).hasSize(1); assertThat(context.getBean("caffeineLoadBalancerCacheManager")) .isInstanceOf(CaffeineCacheManager.class); assertThat( ((CacheManager) context.getBean("caffeineLoadBalancerCacheManager")) .getCacheNames()) .contains("CachingServiceInstanceListSupplierCache"); }); }
Example #3
Source File: AbstractAdapterConfig.java From hono with Eclipse Public License 2.0 | 6 votes |
/** * Create a new cache provider based on Caffeine and Spring Cache. * * @param minCacheSize The minimum size of the cache. * @param maxCacheSize the maximum size of the cache. * @return A new cache provider or {@code null} if no cache should be used. */ private static CacheProvider newCaffeineCache(final int minCacheSize, final long maxCacheSize) { if (maxCacheSize <= 0) { return null; } final Caffeine<Object, Object> caffeine = Caffeine.newBuilder() .initialCapacity(minCacheSize) .maximumSize(Math.max(minCacheSize, maxCacheSize)); final CaffeineCacheManager manager = new CaffeineCacheManager(); manager.setAllowNullValues(false); manager.setCaffeine(caffeine); return new SpringCacheProvider(manager); }
Example #4
Source File: CacheConfiguration.java From hedera-mirror-node with Apache License 2.0 | 5 votes |
@Bean(EXPIRE_AFTER_5M) @Primary CacheManager cacheManager5m() { CaffeineCacheManager caffeineCacheManager = new CaffeineCacheManager(); caffeineCacheManager.setCacheSpecification("maximumSize=100,expireAfterWrite=5m"); return caffeineCacheManager; }
Example #5
Source File: CachingAutoConfigurationTest.java From genie with Apache License 2.0 | 5 votes |
/** * The auto configuration creates the expected beans. */ @Test void expectedBeansExist() { this.contextRunner.run( context -> { // This should be provided by the Spring Boot starter after @EnableCaching is applied Assertions.assertThat(context).hasSingleBean(CacheManager.class); Assertions.assertThat(context).hasSingleBean(CaffeineCacheManager.class); } ); }
Example #6
Source File: CaffeineConfiguration.java From tutorials with MIT License | 5 votes |
@Bean public CacheManager cacheManager(Caffeine caffeine) { CaffeineCacheManager caffeineCacheManager = new CaffeineCacheManager(); caffeineCacheManager.getCache("addresses"); caffeineCacheManager.setCaffeine(caffeine); return caffeineCacheManager; }
Example #7
Source File: LoadBalancerCacheAutoConfigurationTests.java From spring-cloud-commons with Apache License 2.0 | 5 votes |
@Test void shouldNotInstantiateCaffeineLoadBalancerCacheIfDisabled() { ApplicationContextRunner contextRunner = baseApplicationRunner() .withPropertyValues("spring.cloud.loadbalancer.cache.enabled=false") .withUserConfiguration(TestConfiguration.class); contextRunner.run(context -> { assertThat(context.getBeansOfType(CacheManager.class)).hasSize(1); assertThat(context.getBean("cacheManager")) .isInstanceOf(CaffeineCacheManager.class); assertThat(((CacheManager) context.getBean("cacheManager")).getCacheNames()) .isEmpty(); }); }
Example #8
Source File: LoadBalancerCacheAutoConfigurationTests.java From spring-cloud-commons with Apache License 2.0 | 5 votes |
@Test void caffeineLoadBalancerCacheShouldNotOverrideCacheTypeSetting() { ApplicationContextRunner contextRunner = baseApplicationRunner() .withUserConfiguration(TestConfiguration.class) .withPropertyValues("spring.cache.type=none"); contextRunner.run(context -> { assertThat(context.getBeansOfType(CacheManager.class)).hasSize(2); assertThat(context.getBean("caffeineLoadBalancerCacheManager")) .isInstanceOf(CaffeineCacheManager.class); assertThat(context.getBeansOfType(CacheManager.class).get("cacheManager")) .isInstanceOf(NoOpCacheManager.class); }); }
Example #9
Source File: UtilConfiguration.java From kaif with Apache License 2.0 | 5 votes |
@Bean public CacheManager honorRollsCacheManager() { Caffeine<Object, Object> cacheBuilder = Caffeine.newBuilder() .expireAfterWrite(1, TimeUnit.HOURS) .maximumSize(100); CaffeineCacheManager cacheManager = new CaffeineCacheManager("listHonorRoll"); cacheManager.setCaffeine(cacheBuilder); return cacheManager; }
Example #10
Source File: UtilConfiguration.java From kaif with Apache License 2.0 | 5 votes |
/** * short life client app user cache (the cache is Optional<ClientAppUser>), so this is not * distribute-able * * @see {@link io.kaif.model.clientapp.ClientAppDao#findClientAppUserWithCache} */ @Bean public CacheManager findClientAppUserCacheManager() { Caffeine<Object, Object> cacheBuilder = Caffeine.newBuilder() .expireAfterWrite(1, TimeUnit.MINUTES) .maximumSize(1000); CaffeineCacheManager cacheManager = new CaffeineCacheManager("findClientAppUser"); cacheManager.setCaffeine(cacheBuilder); return cacheManager; }
Example #11
Source File: UtilConfiguration.java From kaif with Apache License 2.0 | 5 votes |
/** * administrators cache, refresh every one minutes. no need to distribute if we have multiple * web servers (user just not see new administrators) */ @Bean public CacheManager listAdministratorsCacheManager() { Caffeine<Object, Object> cacheBuilder = Caffeine.newBuilder() .expireAfterWrite(1, TimeUnit.MINUTES) .maximumSize(1000); CaffeineCacheManager cacheManager = new CaffeineCacheManager("listAdministrators"); cacheManager.setCaffeine(cacheBuilder); return cacheManager; }
Example #12
Source File: UtilConfiguration.java From kaif with Apache License 2.0 | 5 votes |
/** * hot zones cache, refresh every one hour. no need to distribute if we have multiple web servers * * @see {@link io.kaif.model.article.ArticleDao#listHotZonesWithCache(int, java.time.Instant)} */ @Bean public CacheManager listHotZonesCacheManager() { Caffeine<Object, Object> cacheBuilder = Caffeine.newBuilder() .expireAfterWrite(1, TimeUnit.HOURS) .maximumSize(1000); CaffeineCacheManager cacheManager = new CaffeineCacheManager("listHotZones"); cacheManager.setCaffeine(cacheBuilder); return cacheManager; }
Example #13
Source File: UtilConfiguration.java From kaif with Apache License 2.0 | 5 votes |
@Bean public CacheManager articleCacheManager() { Caffeine<Object, Object> cacheBuilder = Caffeine.newBuilder() .expireAfterWrite(10, TimeUnit.MINUTES) .maximumSize(2000); CaffeineCacheManager cacheManager = new CaffeineCacheManager("Article"); cacheManager.setCaffeine(cacheBuilder); return cacheManager; }
Example #14
Source File: UtilConfiguration.java From kaif with Apache License 2.0 | 5 votes |
@Bean public CacheManager zoneInfoCacheManager() { Caffeine<Object, Object> cacheBuilder = Caffeine.newBuilder() .expireAfterWrite(10, TimeUnit.MINUTES) .maximumSize(2000); CaffeineCacheManager cacheManager = new CaffeineCacheManager("ZoneInfo"); cacheManager.setCaffeine(cacheBuilder); return cacheManager; }
Example #15
Source File: UtilConfiguration.java From kaif with Apache License 2.0 | 5 votes |
@Bean public CacheManager rssHotArticlesCacheManager() { Caffeine<Object, Object> cacheBuilder = Caffeine.newBuilder() .expireAfterWrite(4, TimeUnit.HOURS) .maximumSize(100); CaffeineCacheManager cacheManager = new CaffeineCacheManager("rssHotArticles"); cacheManager.setCaffeine(cacheBuilder); return cacheManager; }
Example #16
Source File: CacheAutoConfiguration.java From hawkbit with Eclipse Public License 1.0 | 5 votes |
/** * @return the direct cache manager to access without tenant aware * check, cause in sometimes it's necessary to access the cache * directly without having the current tenant, e.g. initial * creation of tenant */ @Bean(name = "directCacheManager") @ConditionalOnMissingBean(name = "directCacheManager") public CacheManager directCacheManager(final CacheProperties cacheProperties) { final CaffeineCacheManager cacheManager = new CaffeineCacheManager(); if (cacheProperties.getTtl() > 0) { final Caffeine<Object, Object> cacheBuilder = Caffeine.newBuilder() .expireAfterWrite(cacheProperties.getTtl(), cacheProperties.getTtlUnit()); cacheManager.setCaffeine(cacheBuilder); } return cacheManager; }
Example #17
Source File: RolloutStatusCache.java From hawkbit with Eclipse Public License 1.0 | 5 votes |
/** * @param tenantAware * to get current tenant * @param size * the maximum size of the cache */ public RolloutStatusCache(final TenantAware tenantAware, final long size) { this.tenantAware = tenantAware; final Caffeine<Object, Object> cacheBuilder = Caffeine.newBuilder().maximumSize(size); final CaffeineCacheManager caffeineCacheManager = new CaffeineCacheManager(); caffeineCacheManager.setCaffeine(cacheBuilder); this.cacheManager = new TenantAwareCacheManager(caffeineCacheManager, tenantAware); }
Example #18
Source File: CachingConfig.java From Spring-5.0-Cookbook with MIT License | 4 votes |
@Bean @Qualifier("caffeineCacheManager") public CaffeineCacheManager caffeineCacheManager() { return new CaffeineCacheManager(); }
Example #19
Source File: CacheConfiguration.java From hedera-mirror-node with Apache License 2.0 | 4 votes |
@Bean(ENTITY_CACHE) CacheManager entityCache(GrpcProperties grpcProperties) { CaffeineCacheManager caffeineCacheManager = new CaffeineCacheManager(); caffeineCacheManager.setCacheSpecification("maximumSize=" + grpcProperties.getEntityCacheSize()); return caffeineCacheManager; }
Example #20
Source File: ArchivedJobServiceImplIntegrationTest.java From genie with Apache License 2.0 | 4 votes |
@Bean CacheManager cacheManager() { // provide a cache manager to test caching return new CaffeineCacheManager(); }
Example #21
Source File: CacheConfig.java From platform with Apache License 2.0 | 4 votes |
@Bean public CacheManagerCustomizer<CaffeineCacheManager> cacheManagerCustomizer() { return cacheManager -> cacheManager.setAllowNullValues(true); }
Example #22
Source File: CacheConfiguration.java From hedera-mirror-node with Apache License 2.0 | 4 votes |
@Bean(EXPIRE_AFTER_30M) CacheManager cacheManager30m() { CaffeineCacheManager caffeineCacheManager = new CaffeineCacheManager(); caffeineCacheManager.setCacheSpecification("maximumSize=10000,expireAfterWrite=30m"); return caffeineCacheManager; }
Example #23
Source File: CacheConfiguration.java From hedera-mirror-node with Apache License 2.0 | 4 votes |
@Bean(TINY_LRU_CACHE) CacheManager tinyLruCache() { CaffeineCacheManager caffeineCacheManager = new CaffeineCacheManager(); caffeineCacheManager.setCacheSpecification("maximumSize=100"); return caffeineCacheManager; }
Example #24
Source File: CachingConfig.java From Spring-5.0-Cookbook with MIT License | 4 votes |
@Bean @Qualifier("caffeineCacheManager") public CaffeineCacheManager caffeineCacheManager() { return new CaffeineCacheManager(); }
Example #25
Source File: CachingConfig.java From Spring-5.0-Cookbook with MIT License | 4 votes |
@Bean @Qualifier("caffeineCacheManager") public CaffeineCacheManager caffeineCacheManager() { return new CaffeineCacheManager(); }
Example #26
Source File: CachingConfig.java From Spring-5.0-Cookbook with MIT License | 4 votes |
@Bean @Qualifier("caffeineCacheManager") public CaffeineCacheManager caffeineCacheManager() { return new CaffeineCacheManager(); }
Example #27
Source File: CachingConfig.java From Spring-5.0-Cookbook with MIT License | 4 votes |
@Bean @Qualifier("caffeineCacheManager") public CaffeineCacheManager caffeineCacheManager() { return new CaffeineCacheManager(); }
Example #28
Source File: CachingConfig.java From Spring-5.0-Cookbook with MIT License | 4 votes |
@Bean @Qualifier("caffeineCacheManager") public CaffeineCacheManager caffeineCacheManager() { return new CaffeineCacheManager(); }
Example #29
Source File: CachingConfig.java From Spring-5.0-Cookbook with MIT License | 4 votes |
@Bean @Qualifier("caffeineCacheManager") public CaffeineCacheManager caffeineCacheManager() { return new CaffeineCacheManager(); }
Example #30
Source File: CachingConfig.java From Spring-5.0-Cookbook with MIT License | 4 votes |
@Bean @Qualifier("caffeineCacheManager") public CaffeineCacheManager caffeineCacheManager() { return new CaffeineCacheManager(); }