public < Result , Param extends Resource > Result execWithTemporaryCaching ( Param resource , IUnitOfWork < Result , Param > transaction ) throws WrappedException { CacheAdapter cacheAdapter = getOrCreate ( resource ) ; IgnoreValuesMemento memento = cacheAdapter . ignoreNewValues ( ) ; try { return transaction . exec ( resource ) ; } catch ( Exception e ) { throw new WrappedException ( e ) ; } finally { memento . done ( ) ; } }
The transaction will be executed with caching enabled . However all newly cached values will be discarded as soon as the transaction is over .