Search in sources :

Example 1 with CacheManager

use of cn.taketoday.cache.CacheManager in project today-infrastructure by TAKETODAY.

the class AbstractCacheAnnotationTests method testCustomCacheManager.

@Test
public void testCustomCacheManager() {
    CacheManager customCm = this.ctx.getBean("customCacheManager", CacheManager.class);
    Object key = new Object();
    Object r1 = this.cs.customCacheManager(key);
    assertThat(this.cs.customCacheManager(key)).isSameAs(r1);
    Cache cache = customCm.getCache("testCache");
    assertThat(cache.get(key)).isNotNull();
}
Also used : CacheManager(cn.taketoday.cache.CacheManager) Cache(cn.taketoday.cache.Cache) Test(org.junit.jupiter.api.Test)

Example 2 with CacheManager

use of cn.taketoday.cache.CacheManager in project today-infrastructure by TAKETODAY.

the class AbstractCacheAnnotationTests method testCustomCacheManager.

@Test
public void testCustomCacheManager() {
    CacheManager customCm = this.ctx.getBean("customCacheManager", CacheManager.class);
    Object key = new Object();
    Object r1 = this.cs.customCacheManager(key);
    assertThat(this.cs.customCacheManager(key)).isSameAs(r1);
    Cache cache = customCm.getCache("testCache");
    assertThat(cache.get(key)).isNotNull();
}
Also used : CacheManager(cn.taketoday.cache.CacheManager) Cache(cn.taketoday.cache.Cache) Test(org.junit.jupiter.api.Test)

Example 3 with CacheManager

use of cn.taketoday.cache.CacheManager in project today-infrastructure by TAKETODAY.

the class AbstractCacheAnnotationTests method testCustomCacheManager.

@Test
public void testCustomCacheManager() {
    CacheManager customCm = this.ctx.getBean("customCacheManager", CacheManager.class);
    Object key = new Object();
    Object r1 = this.cs.customCacheManager(key);
    assertThat(this.cs.customCacheManager(key)).isSameAs(r1);
    Cache cache = customCm.getCache("testCache");
    assertThat(cache.get(key)).isNotNull();
}
Also used : CacheManager(cn.taketoday.cache.CacheManager) Cache(cn.taketoday.cache.Cache) Test(org.junit.jupiter.api.Test)

Example 4 with CacheManager

use of cn.taketoday.cache.CacheManager in project today-infrastructure by TAKETODAY.

the class CacheResolverCustomizationTests method setup.

@BeforeEach
public void setup() {
    ApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
    this.cacheManager = context.getBean("cacheManager", CacheManager.class);
    this.anotherCacheManager = context.getBean("anotherCacheManager", CacheManager.class);
    this.simpleService = context.getBean(SimpleService.class);
}
Also used : AnnotationConfigApplicationContext(cn.taketoday.context.annotation.AnnotationConfigApplicationContext) ApplicationContext(cn.taketoday.context.ApplicationContext) AnnotationConfigApplicationContext(cn.taketoday.context.annotation.AnnotationConfigApplicationContext) CacheManager(cn.taketoday.cache.CacheManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with CacheManager

use of cn.taketoday.cache.CacheManager in project today-framework by TAKETODAY.

the class AbstractCacheResolver method resolveCaches.

@Override
public Collection<? extends Cache> resolveCaches(CacheOperationInvocationContext<?> context) {
    Collection<String> cacheNames = getCacheNames(context);
    if (cacheNames == null) {
        return Collections.emptyList();
    }
    ArrayList<Cache> result = new ArrayList<>(cacheNames.size());
    CacheManager cacheManager = getCacheManager();
    for (String cacheName : cacheNames) {
        Cache cache = cacheManager.getCache(cacheName);
        if (cache == null) {
            throw new IllegalArgumentException("Cannot find cache named '" + cacheName + "' for " + context.getOperation());
        }
        result.add(cache);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) CacheManager(cn.taketoday.cache.CacheManager) Cache(cn.taketoday.cache.Cache)

Aggregations

CacheManager (cn.taketoday.cache.CacheManager)14 Cache (cn.taketoday.cache.Cache)12 Test (org.junit.jupiter.api.Test)10 CaffeineCache (cn.taketoday.cache.support.CaffeineCache)2 CaffeineCacheManager (cn.taketoday.cache.support.CaffeineCacheManager)2 ApplicationContext (cn.taketoday.context.ApplicationContext)2 AnnotationConfigApplicationContext (cn.taketoday.context.annotation.AnnotationConfigApplicationContext)2 ArrayList (java.util.ArrayList)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2