Search in sources :

Example 1 with ConcurrentMapCache

use of cn.taketoday.cache.concurrent.ConcurrentMapCache in project today-infrastructure 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 2 with ConcurrentMapCache

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

the class EncodedResourceResolverTests method setup.

@BeforeEach
public void setup() {
    this.cache = new ConcurrentMapCache("resourceCache");
    VersionResourceResolver versionResolver = new VersionResourceResolver();
    versionResolver.setStrategyMap(Collections.singletonMap("/**", new ContentVersionStrategy()));
    List<ResourceResolver> resolvers = new ArrayList<>();
    resolvers.add(new CachingResourceResolver(this.cache));
    resolvers.add(new EncodedResourceResolver());
    resolvers.add(versionResolver);
    resolvers.add(new PathResourceResolver());
    this.resolver = new DefaultResourceResolvingChain(resolvers);
    this.locations = new ArrayList<>();
    this.locations.add(new ClassPathResource("test/", getClass()));
    this.locations.add(new ClassPathResource("testalternatepath/", 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 3 with ConcurrentMapCache

use of cn.taketoday.cache.concurrent.ConcurrentMapCache in project today-infrastructure 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 4 with ConcurrentMapCache

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

the class ExpressionEvaluatorTests method testMultipleCachingEval.

@Test
public void testMultipleCachingEval() {
    AnnotatedClass target = new AnnotatedClass();
    Method method = ReflectionUtils.findMethod(AnnotatedClass.class, "multipleCaching", Object.class, Object.class);
    Object[] args = new Object[] { new Object(), new Object() };
    Collection<ConcurrentMapCache> caches = Collections.singleton(new ConcurrentMapCache("test"));
    EvaluationContext evalCtx = this.eval.createEvaluationContext(caches, method, args, target, target.getClass(), method, CacheOperationExpressionEvaluator.NO_RESULT, null);
    Collection<CacheOperation> ops = getOps("multipleCaching");
    Iterator<CacheOperation> it = ops.iterator();
    AnnotatedElementKey key = new AnnotatedElementKey(method, AnnotatedClass.class);
    Object keyA = this.eval.key(it.next().getKey(), key, evalCtx);
    Object keyB = this.eval.key(it.next().getKey(), key, evalCtx);
    assertThat(keyA).isEqualTo(args[0]);
    assertThat(keyB).isEqualTo(args[1]);
}
Also used : ConcurrentMapCache(cn.taketoday.cache.concurrent.ConcurrentMapCache) Method(java.lang.reflect.Method) EvaluationContext(cn.taketoday.expression.EvaluationContext) AnnotatedElementKey(cn.taketoday.context.expression.AnnotatedElementKey) Test(org.junit.jupiter.api.Test)

Example 5 with ConcurrentMapCache

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

the class TransactionAwareCacheDecoratorTests method evictIfPresentNonTransactional.

@Test
public void evictIfPresentNonTransactional() {
    Cache target = new ConcurrentMapCache("testCache");
    Cache cache = new TransactionAwareCacheDecorator(target);
    Object key = new Object();
    cache.put(key, "123");
    cache.evictIfPresent(key);
    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)

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