use of org.springframework.cache.concurrent.ConcurrentMapCache in project spring-framework by spring-projects.
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 org.springframework.cache.concurrent.ConcurrentMapCache in project spring-framework by spring-projects.
the class TransactionAwareCacheDecoratorTests method clearNonTransactional.
@Test
public void clearNonTransactional() {
Cache target = new ConcurrentMapCache("testCache");
Cache cache = new TransactionAwareCacheDecorator(target);
Object key = new Object();
cache.put(key, "123");
cache.clear();
assertNull(target.get(key));
}
use of org.springframework.cache.concurrent.ConcurrentMapCache in project spring-framework by spring-projects.
the class TransactionAwareCacheDecoratorTests method evictNonTransactional.
@Test
public void evictNonTransactional() {
Cache target = new ConcurrentMapCache("testCache");
Cache cache = new TransactionAwareCacheDecorator(target);
Object key = new Object();
cache.put(key, "123");
cache.evict(key);
assertNull(target.get(key));
}
use of org.springframework.cache.concurrent.ConcurrentMapCache in project spring-framework by spring-projects.
the class TransactionAwareCacheDecoratorTests method putTransactional.
@Test
public void putTransactional() {
Cache target = new ConcurrentMapCache("testCache");
Cache cache = new TransactionAwareCacheDecorator(target);
TransactionStatus status = txManager.getTransaction(new DefaultTransactionAttribute(TransactionDefinition.PROPAGATION_REQUIRED));
Object key = new Object();
cache.put(key, "123");
assertNull(target.get(key));
txManager.commit(status);
assertEquals("123", target.get(key, String.class));
}
use of org.springframework.cache.concurrent.ConcurrentMapCache in project spring-framework by spring-projects.
the class TransactionAwareCacheDecoratorTests method putIfAbsent.
@Test
public void putIfAbsent() {
// no transactional support for putIfAbsent
Cache target = new ConcurrentMapCache("testCache");
Cache cache = new TransactionAwareCacheDecorator(target);
Object key = new Object();
assertNull(cache.putIfAbsent(key, "123"));
assertEquals("123", target.get(key, String.class));
assertEquals("123", cache.putIfAbsent(key, "456").get());
// unchanged
assertEquals("123", target.get(key, String.class));
}
Aggregations