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