private void setupCacheThrough ( ) { if ( config . getCacheLoaderFactory ( ) != null ) { final CacheLoader < K , V > clf = config . getCacheLoaderFactory ( ) . create ( ) ; cache2kConfiguration . setAdvancedLoader ( new CustomizationReferenceSupplier < AdvancedCacheLoader < K , V > > ( new CloseableLoader ( ) { @ Override public void close ( ) throws IOException { if ( clf instanceof Closeable ) { ( ( Closeable ) clf ) . close ( ) ; } } @ Override public V load ( final K key , final long currentTime , final CacheEntry < K , V > currentEntry ) { return clf . load ( key ) ; } } ) ) ; } if ( config . getCacheWriterFactory ( ) != null ) { final javax . cache . integration . CacheWriter < ? super K , ? super V > cw = config . getCacheWriterFactory ( ) . create ( ) ; cache2kConfiguration . setWriter ( new CustomizationReferenceSupplier < CacheWriter < K , V > > ( new CloseableWriter ( ) { @ Override public void write ( final K key , final V value ) { Cache . Entry < K , V > ce = new Cache . Entry < K , V > ( ) { @ Override public K getKey ( ) { return key ; } @ Override public V getValue ( ) { return value ; } @ Override public < T > T unwrap ( Class < T > clazz ) { throw new UnsupportedOperationException ( "unwrap entry not supported" ) ; } } ; cw . write ( ce ) ; } @ Override public void delete ( final Object key ) { cw . delete ( key ) ; } @ Override public void close ( ) throws IOException { if ( cw instanceof Closeable ) { ( ( Closeable ) cw ) . close ( ) ; } } } ) ) ; } }
Configure loader and writer .