Search in sources :

Example 11 with ConcurrentMapCache

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

the class TransactionAwareCacheDecoratorTests method getTargetCache.

@Test
public void getTargetCache() {
    Cache target = new ConcurrentMapCache("testCache");
    TransactionAwareCacheDecorator cache = new TransactionAwareCacheDecorator(target);
    assertThat(cache.getTargetCache()).isSameAs(target);
}
Also used : ConcurrentMapCache(cn.taketoday.cache.concurrent.ConcurrentMapCache) ConcurrentMapCache(cn.taketoday.cache.concurrent.ConcurrentMapCache) Cache(cn.taketoday.cache.Cache) Test(org.junit.jupiter.api.Test)

Example 12 with ConcurrentMapCache

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

the class CacheTestUtils method createSimpleCacheManager.

/**
 * Create a {@link SimpleCacheManager} with the specified cache(s).
 * @param cacheNames the names of the caches to create
 */
public static CacheManager createSimpleCacheManager(String... cacheNames) {
    SimpleCacheManager result = new SimpleCacheManager();
    List<Cache> caches = new ArrayList<>();
    for (String cacheName : cacheNames) {
        caches.add(new ConcurrentMapCache(cacheName));
    }
    result.setCaches(caches);
    result.afterPropertiesSet();
    return result;
}
Also used : ConcurrentMapCache(cn.taketoday.cache.concurrent.ConcurrentMapCache) ArrayList(java.util.ArrayList) SimpleCacheManager(cn.taketoday.cache.support.SimpleCacheManager) ConcurrentMapCache(cn.taketoday.cache.concurrent.ConcurrentMapCache) Cache(cn.taketoday.cache.Cache)

Example 13 with ConcurrentMapCache

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

the class CachingResourceResolverTests method setup.

@BeforeEach
public void setup() {
    this.cache = new ConcurrentMapCache("resourceCache");
    List<ResourceResolver> resolvers = new ArrayList<>();
    resolvers.add(new CachingResourceResolver(this.cache));
    resolvers.add(new PathResourceResolver());
    this.chain = new DefaultResourceResolvingChain(resolvers);
    this.locations = new ArrayList<>();
    this.locations.add(new ClassPathResource("test/", getClass()));
}
Also used : ConcurrentMapCache(cn.taketoday.cache.concurrent.ConcurrentMapCache) ArrayList(java.util.ArrayList) ClassPathResource(cn.taketoday.core.io.ClassPathResource) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 14 with ConcurrentMapCache

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

the class TransactionAwareCacheDecoratorTests method regularOperationsOnTarget.

@Test
public void regularOperationsOnTarget() {
    Cache target = new ConcurrentMapCache("testCache");
    Cache cache = new TransactionAwareCacheDecorator(target);
    assertThat(cache.getName()).isEqualTo(target.getName());
    assertThat(cache.getNativeCache()).isEqualTo(target.getNativeCache());
    Object key = new Object();
    target.put(key, "123");
    assertThat(cache.get(key).get()).isEqualTo("123");
    assertThat(cache.get(key, String.class)).isEqualTo("123");
    cache.clear();
    assertThat(target.get(key)).isNull();
}
Also used : ConcurrentMapCache(cn.taketoday.cache.concurrent.ConcurrentMapCache) ConcurrentMapCache(cn.taketoday.cache.concurrent.ConcurrentMapCache) Cache(cn.taketoday.cache.Cache) Test(org.junit.jupiter.api.Test)

Example 15 with ConcurrentMapCache

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

the class TransactionAwareCacheDecoratorTests method putIfAbsentNonTransactional.

@Test
public void putIfAbsentNonTransactional() {
    Cache target = new ConcurrentMapCache("testCache");
    Cache cache = new TransactionAwareCacheDecorator(target);
    Object key = new Object();
    assertThat(cache.putIfAbsent(key, "123")).isNull();
    assertThat(target.get(key, String.class)).isEqualTo("123");
    assertThat(cache.putIfAbsent(key, "456").get()).isEqualTo("123");
    // unchanged
    assertThat(target.get(key, String.class)).isEqualTo("123");
}
Also used : ConcurrentMapCache(cn.taketoday.cache.concurrent.ConcurrentMapCache) ConcurrentMapCache(cn.taketoday.cache.concurrent.ConcurrentMapCache) Cache(cn.taketoday.cache.Cache) Test(org.junit.jupiter.api.Test)

Aggregations

ConcurrentMapCache (cn.taketoday.cache.concurrent.ConcurrentMapCache)42 Cache (cn.taketoday.cache.Cache)34 Test (org.junit.jupiter.api.Test)30 ArrayList (java.util.ArrayList)10 SimpleCacheManager (cn.taketoday.cache.support.SimpleCacheManager)6 ClassPathResource (cn.taketoday.core.io.ClassPathResource)4 Method (java.lang.reflect.Method)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 AnnotatedElementKey (cn.taketoday.context.expression.AnnotatedElementKey)2 EvaluationContext (cn.taketoday.expression.EvaluationContext)2