Java Code Examples for org.springframework.cache.transaction.TransactionAwareCacheDecorator

Following code examples demonstrate how to use org.springframework.cache.transaction.TransactionAwareCacheDecoratorfrom spring-framework. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.springframework.cache.transaction.TransactionAwareCacheDecoratorand various code implementation of this class.

		private static Cache unwrapIfNecessary(Cache cache) {
			try {
				if (cache instanceof TransactionAwareCacheDecorator) {
					return ((TransactionAwareCacheDecorator) cache).getTargetCache();
				}
			}
			catch (NoClassDefFoundError ex) {
			}
			return cache;
		} 


    public Cache cacheManager() {
        CacheManager cacheManager = new ConcurrentMapCacheManager(CACHE);
        return new TransactionAwareCacheDecorator(cacheManager.getCache(CACHE));
    } 

Advertisement
Javadoc
Cache decorator which synchronizes its #put, #evict and #clear operations with Spring-managed transa

ctions (through Spring's TransactionSynchronizationManager, performing the actual cache put/evict/clear operation only in the after-commit phase of a successful transaction. If no transaction is active, #put, #evict and #clear operations will be performed immediately, as usual.

Use of more aggressive operations such as #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

Read More
Advertisement