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;
}
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()));
}
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()));
}
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]);
}
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();
}
Aggregations