Skip to content
Snippets Groups Projects
Commit 0edd903f authored by Tobias Pietzsch's avatar Tobias Pietzsch
Browse files

Use revised caches

VolatileGlobalCellCache now builds on a WeakRefVolatileCache backed by a
SoftRefCache.
parent 20b95000
No related branches found
No related tags found
No related merge requests found
...@@ -29,15 +29,20 @@ ...@@ -29,15 +29,20 @@
*/ */
package bdv.img.cache; package bdv.img.cache;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import bdv.cache.CacheControl; import bdv.cache.CacheControl;
import bdv.cache.CacheHints; import bdv.cache.CacheHints;
import bdv.cache.LoadingVolatileCache; import bdv.cache.revised.Cache;
import bdv.cache.VolatileCacheValueLoader; import bdv.cache.revised.SoftRefCache;
import bdv.cache.WeakSoftCache; import bdv.cache.revised.VolatileCache;
import bdv.cache.revised.VolatileLoader;
import bdv.cache.revised.WeakRefVolatileCache;
import bdv.cache.util.BlockingFetchQueues; import bdv.cache.util.BlockingFetchQueues;
import bdv.cache.util.FetcherThreads;
import bdv.img.cache.VolatileImgCells.CellCache; import bdv.img.cache.VolatileImgCells.CellCache;
import net.imglib2.img.basictypeaccess.volatiles.VolatileAccess; import net.imglib2.img.basictypeaccess.volatiles.VolatileAccess;
import net.imglib2.img.cell.CellImg;
public class VolatileGlobalCellCache implements CacheControl public class VolatileGlobalCellCache implements CacheControl
{ {
...@@ -103,13 +108,13 @@ public class VolatileGlobalCellCache implements CacheControl ...@@ -103,13 +108,13 @@ public class VolatileGlobalCellCache implements CacheControl
} }
} }
private final WeakSoftCacheFactory cacheFactory = new WeakSoftCacheFactory(); private final BlockingFetchQueues< Callable< ? > > queue;
private final BlockingFetchQueues< Loader > queue;
private final FetcherThreads fetchers; private final FetcherThreads fetchers;
protected final LoadingVolatileCache< Key, VolatileCell< ? > > volatileCache; // TODO rename protected final Cache< Key, VolatileCell< ? > > backingCache;
protected final VolatileCache< Key, VolatileCell< ? > > volatileCache; // TODO rename
/** /**
* @param maxNumLevels * @param maxNumLevels
...@@ -120,7 +125,8 @@ public class VolatileGlobalCellCache implements CacheControl ...@@ -120,7 +125,8 @@ public class VolatileGlobalCellCache implements CacheControl
{ {
queue = new BlockingFetchQueues<>( maxNumLevels ); queue = new BlockingFetchQueues<>( maxNumLevels );
fetchers = new FetcherThreads( queue, numFetcherThreads ); fetchers = new FetcherThreads( queue, numFetcherThreads );
volatileCache = new LoadingVolatileCache<>( cacheFactory, queue ); backingCache = new SoftRefCache<>();
volatileCache = new WeakRefVolatileCache<>( backingCache, queue );
} }
/** /**
...@@ -147,7 +153,6 @@ public class VolatileGlobalCellCache implements CacheControl ...@@ -147,7 +153,6 @@ public class VolatileGlobalCellCache implements CacheControl
public void prepareNextFrame() public void prepareNextFrame()
{ {
queue.clearToPrefetch(); queue.clearToPrefetch();
cacheFactory.cleanUp();
} }
/** /**
...@@ -157,6 +162,7 @@ public class VolatileGlobalCellCache implements CacheControl ...@@ -157,6 +162,7 @@ public class VolatileGlobalCellCache implements CacheControl
public void clearCache() public void clearCache()
{ {
volatileCache.invalidateAll(); volatileCache.invalidateAll();
backingCache.invalidateAll();
queue.clear(); queue.clear();
} }
...@@ -169,15 +175,16 @@ public class VolatileGlobalCellCache implements CacheControl ...@@ -169,15 +175,16 @@ public class VolatileGlobalCellCache implements CacheControl
* *
* @return the cache that handles cell loading * @return the cache that handles cell loading
*/ */
public LoadingVolatileCache< Key, VolatileCell< ? > > getLoadingVolatileCache() // TODO
{ // public LoadingVolatileCache< Key, VolatileCell< ? > > getLoadingVolatileCache()
return volatileCache; // {
} // return volatileCache;
// }
/** /**
* A {@link VolatileCacheValueLoader} for one specific {@link VolatileCell}. * A {@link VolatileCacheValueLoader} for one specific {@link VolatileCell}.
*/ */
public static class VolatileCellLoader< A extends VolatileAccess > implements VolatileCacheValueLoader< VolatileCell< A > > public static class VolatileCellLoader< A extends VolatileAccess > implements VolatileLoader< VolatileCell< A > >
{ {
private final CacheArrayLoader< A > cacheArrayLoader; private final CacheArrayLoader< A > cacheArrayLoader;
...@@ -225,15 +232,15 @@ public class VolatileGlobalCellCache implements CacheControl ...@@ -225,15 +232,15 @@ public class VolatileGlobalCellCache implements CacheControl
} }
@Override @Override
public VolatileCell< A > createEmptyValue() public VolatileCell< A > call() throws Exception
{ {
return new VolatileCell<>( cellDims, cellMin, cacheArrayLoader.emptyArray( cellDims ) ); return new VolatileCell<>( cellDims, cellMin, cacheArrayLoader.loadArray( timepoint, setup, level, cellDims, cellMin ) );
} }
@Override @Override
public VolatileCell< A > load() throws InterruptedException public VolatileCell< A > createInvalid()
{ {
return new VolatileCell<>( cellDims, cellMin, cacheArrayLoader.loadArray( timepoint, setup, level, cellDims, cellMin ) ); return new VolatileCell<>( cellDims, cellMin, cacheArrayLoader.emptyArray( cellDims ) );
} }
} }
...@@ -270,7 +277,14 @@ public class VolatileGlobalCellCache implements CacheControl ...@@ -270,7 +277,14 @@ public class VolatileGlobalCellCache implements CacheControl
public VolatileCell< A > get( final long index ) public VolatileCell< A > get( final long index )
{ {
final Key key = new Key( timepoint, setup, level, index ); final Key key = new Key( timepoint, setup, level, index );
return ( VolatileCell< A > ) volatileCache.getIfPresent( key, cacheHints ); try
{
return ( VolatileCell< A > ) volatileCache.getIfPresent( key, cacheHints );
}
catch ( final ExecutionException e )
{
throw new RuntimeException( e );
}
} }
@SuppressWarnings( "unchecked" ) @SuppressWarnings( "unchecked" )
...@@ -279,7 +293,14 @@ public class VolatileGlobalCellCache implements CacheControl ...@@ -279,7 +293,14 @@ public class VolatileGlobalCellCache implements CacheControl
{ {
final Key key = new Key( timepoint, setup, level, index ); final Key key = new Key( timepoint, setup, level, index );
final VolatileCellLoader< A > loader = new VolatileCellLoader<>( cacheArrayLoader, timepoint, setup, level, cellDims, cellMin ); final VolatileCellLoader< A > loader = new VolatileCellLoader<>( cacheArrayLoader, timepoint, setup, level, cellDims, cellMin );
return ( VolatileCell< A > ) volatileCache.get( key, cacheHints, loader ); try
{
return ( VolatileCell< A > ) volatileCache.get( key, loader, cacheHints );
}
catch ( final ExecutionException e )
{
throw new RuntimeException( e );
}
} }
@Override @Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment