@ -22,17 +22,18 @@ import org.springframework.transaction.support.TransactionSynchronizationManager
@@ -22,17 +22,18 @@ import org.springframework.transaction.support.TransactionSynchronizationManager
import org.springframework.util.Assert ;
/ * *
* Cache decorator which synchronizes its { @link # put } and { @link # evict } operations with
* Spring - managed transactions ( through Spring ' s { @link TransactionSynchronizationManager } ,
* performing the actual cache put / evict operation only in the after - commit phase of a
* successful transaction . If no transaction is active , { @link # put } and { @link # evict }
* operations will be performed immediately , as usual .
* Cache decorator which synchronizes its { @link # put } , { @link # evict } and { @link # clear }
* operations with Spring - managed transactions ( through Spring ' s { @link TransactionSynchronizationManager } ,
* performing the actual cache put / evict / clear operation only in the after - commit phase of a
* successful transaction . If no transaction is active , { @link # put } , { @link # evict } and
* { @link # clear } operations will be performed immediately , as usual .
*
* < p > Use of more aggressive operations such as { @link # putIfAbsent } cannot be deferred
* to the after - commit phase of a running transaction . Use these with care .
*
* @author Juergen Hoeller
* @author Stephane Nicoll
* @author Stas Volsky
* @since 3 . 2
* @see TransactionAwareCacheManagerProxy
* /
@ -108,7 +109,17 @@ public class TransactionAwareCacheDecorator implements Cache {
@@ -108,7 +109,17 @@ public class TransactionAwareCacheDecorator implements Cache {
@Override
public void clear ( ) {
this . targetCache . clear ( ) ;
if ( TransactionSynchronizationManager . isSynchronizationActive ( ) ) {
TransactionSynchronizationManager . registerSynchronization ( new TransactionSynchronizationAdapter ( ) {
@Override
public void afterCommit ( ) {
targetCache . clear ( ) ;
}
} ) ;
}
else {
this . targetCache . clear ( ) ;
}
}
}