Synchronize clear on TransactionAwareCacheDecorator
Previously, a cache decorated with TransactionAwareCacheDecorator would clear the cache immediately, even when a transaction is running. This commit updates the decorator to synchronize to the afterCommit phase for the clear operation as well. Issue: SPR-12653
This commit is contained in:
committed by
Stephane Nicoll
parent
6b3092c236
commit
ef95fc2f7e
@@ -128,4 +128,31 @@ public class TransactionAwareCacheDecoratorTests {
|
||||
assertNull(target.get(key));
|
||||
}
|
||||
|
||||
@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));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clearTransactional() {
|
||||
Cache target = new ConcurrentMapCache("testCache");
|
||||
Cache cache = new TransactionAwareCacheDecorator(target);
|
||||
Object key = new Object();
|
||||
cache.put(key, "123");
|
||||
|
||||
|
||||
TransactionStatus status = txManager.getTransaction(new DefaultTransactionAttribute(
|
||||
TransactionDefinition.PROPAGATION_REQUIRED));
|
||||
cache.clear();
|
||||
assertEquals("123", target.get(key, String.class));
|
||||
txManager.commit(status);
|
||||
|
||||
assertNull(target.get(key));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user