Search in sources :

Example 1 with CaffeineCache

use of org.springframework.cache.caffeine.CaffeineCache in project spring-boot by spring-projects.

the class CacheAutoConfigurationTests method validateCaffeineCacheWithStats.

private void validateCaffeineCacheWithStats() {
    CaffeineCacheManager cacheManager = validateCacheManager(CaffeineCacheManager.class);
    assertThat(cacheManager.getCacheNames()).containsOnly("foo", "bar");
    Cache foo = cacheManager.getCache("foo");
    foo.get("1");
    assertThat(((CaffeineCache) foo).getNativeCache().stats().missCount()).isEqualTo(1L);
}
Also used : CaffeineCacheManager(org.springframework.cache.caffeine.CaffeineCacheManager) CaffeineCache(org.springframework.cache.caffeine.CaffeineCache) ConcurrentMapCache(org.springframework.cache.concurrent.ConcurrentMapCache) Cache(org.springframework.cache.Cache) CaffeineCache(org.springframework.cache.caffeine.CaffeineCache) CouchbaseCache(com.couchbase.client.spring.cache.CouchbaseCache)

Example 2 with CaffeineCache

use of org.springframework.cache.caffeine.CaffeineCache in project spring-boot by spring-projects.

the class CacheAutoConfigurationTests method caffeineCacheWithExplicitCaches.

@Test
public void caffeineCacheWithExplicitCaches() {
    load(DefaultCacheConfiguration.class, "spring.cache.type=caffeine", "spring.cache.cacheNames=foo");
    CaffeineCacheManager cacheManager = validateCacheManager(CaffeineCacheManager.class);
    assertThat(cacheManager.getCacheNames()).containsOnly("foo");
    Cache foo = cacheManager.getCache("foo");
    foo.get("1");
    // See next tests: no spec given so stats should be disabled
    assertThat(((CaffeineCache) foo).getNativeCache().stats().missCount()).isEqualTo(0L);
}
Also used : CaffeineCacheManager(org.springframework.cache.caffeine.CaffeineCacheManager) CaffeineCache(org.springframework.cache.caffeine.CaffeineCache) ConcurrentMapCache(org.springframework.cache.concurrent.ConcurrentMapCache) Cache(org.springframework.cache.Cache) CaffeineCache(org.springframework.cache.caffeine.CaffeineCache) CouchbaseCache(com.couchbase.client.spring.cache.CouchbaseCache) Test(org.junit.Test)

Example 3 with CaffeineCache

use of org.springframework.cache.caffeine.CaffeineCache in project thingsboard by thingsboard.

the class CaffeineCacheConfiguration method cacheManager.

@Bean
public CacheManager cacheManager() {
    SimpleCacheManager manager = new SimpleCacheManager();
    if (specs != null) {
        List<CaffeineCache> caches = specs.entrySet().stream().map(entry -> buildCache(entry.getKey(), entry.getValue())).collect(Collectors.toList());
        manager.setCaches(caches);
    }
    return manager;
}
Also used : Ticker(com.github.benmanes.caffeine.cache.Ticker) Caffeine(com.github.benmanes.caffeine.cache.Caffeine) SimpleCacheManager(org.springframework.cache.support.SimpleCacheManager) KeyGenerator(org.springframework.cache.interceptor.KeyGenerator) ConfigurationProperties(org.springframework.boot.context.properties.ConfigurationProperties) Collectors(java.util.stream.Collectors) Configuration(org.springframework.context.annotation.Configuration) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) CacheManager(org.springframework.cache.CacheManager) Map(java.util.Map) Data(lombok.Data) CaffeineCache(org.springframework.cache.caffeine.CaffeineCache) Bean(org.springframework.context.annotation.Bean) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty) EnableCaching(org.springframework.cache.annotation.EnableCaching) CaffeineCache(org.springframework.cache.caffeine.CaffeineCache) SimpleCacheManager(org.springframework.cache.support.SimpleCacheManager) Bean(org.springframework.context.annotation.Bean)

Example 4 with CaffeineCache

use of org.springframework.cache.caffeine.CaffeineCache in project faf-java-server by FAForever.

the class CacheConfig method cacheManager.

@Bean
public CacheManager cacheManager() {
    SimpleCacheManager cacheManager = new SimpleCacheManager();
    cacheManager.setCaches(Arrays.asList(new CaffeineCache(CacheNames.FEATURED_MODS, newBuilder().expireAfterWrite(5, MINUTES).build()), new CaffeineCache(CacheNames.RANKED_MODS, newBuilder().expireAfterWrite(5, MINUTES).build()), new CaffeineCache(CacheNames.MAP_VERSIONS, newBuilder().expireAfterAccess(5, MINUTES).build())));
    return cacheManager;
}
Also used : CaffeineCache(org.springframework.cache.caffeine.CaffeineCache) SimpleCacheManager(org.springframework.cache.support.SimpleCacheManager) Bean(org.springframework.context.annotation.Bean)

Example 5 with CaffeineCache

use of org.springframework.cache.caffeine.CaffeineCache in project commons-dao by reportportal.

the class CacheConfiguration method getGlobalCacheManager.

/**
 * Global Cache Manager
 */
@Bean
public CacheManager getGlobalCacheManager() {
    SimpleCacheManager cacheManager = new SimpleCacheManager();
    // @formatter:off
    CaffeineCache tickets = new CaffeineCache(EXTERNAL_SYSTEM_TICKET_CACHE, Caffeine.newBuilder().maximumSize(ticketCacheSize).softValues().expireAfterAccess(ticketCacheExpiration, TimeUnit.MINUTES).build());
    CaffeineCache projects = new CaffeineCache(JIRA_PROJECT_CACHE, Caffeine.newBuilder().maximumSize(projectCacheSize).softValues().expireAfterAccess(projectCacheExpiration, TimeUnit.DAYS).build());
    CaffeineCache projectInfo = new CaffeineCache(PROJECT_INFO_CACHE, Caffeine.newBuilder().maximumSize(projectCacheSize).softValues().expireAfterWrite(projectInfoCacheExpiration, TimeUnit.MINUTES).build());
    cacheManager.setCaches(ImmutableList.<Cache>builder().add(tickets).add(projects).add(projectInfo).build());
    return cacheManager;
}
Also used : CaffeineCache(org.springframework.cache.caffeine.CaffeineCache) SimpleCacheManager(org.springframework.cache.support.SimpleCacheManager) Bean(org.springframework.context.annotation.Bean)

Aggregations

CaffeineCache (org.springframework.cache.caffeine.CaffeineCache)5 SimpleCacheManager (org.springframework.cache.support.SimpleCacheManager)3 Bean (org.springframework.context.annotation.Bean)3 CouchbaseCache (com.couchbase.client.spring.cache.CouchbaseCache)2 Cache (org.springframework.cache.Cache)2 CaffeineCacheManager (org.springframework.cache.caffeine.CaffeineCacheManager)2 ConcurrentMapCache (org.springframework.cache.concurrent.ConcurrentMapCache)2 Caffeine (com.github.benmanes.caffeine.cache.Caffeine)1 Ticker (com.github.benmanes.caffeine.cache.Ticker)1 List (java.util.List)1 Map (java.util.Map)1 TimeUnit (java.util.concurrent.TimeUnit)1 Collectors (java.util.stream.Collectors)1 Data (lombok.Data)1 Test (org.junit.Test)1 ConditionalOnProperty (org.springframework.boot.autoconfigure.condition.ConditionalOnProperty)1 ConfigurationProperties (org.springframework.boot.context.properties.ConfigurationProperties)1 CacheManager (org.springframework.cache.CacheManager)1 EnableCaching (org.springframework.cache.annotation.EnableCaching)1 KeyGenerator (org.springframework.cache.interceptor.KeyGenerator)1