Package org.apache.sis.image
Class TileCache
- All Implemented Interfaces:
ConcurrentMap<TileCache.Key,
,Raster> Map<TileCache.Key,
Raster>
A cache of tiles computed by
ComputedImage
. A common cache is shared by all images.
Tiles are kept by strong references until a memory usage limit is reached, in which case
the references of oldest tiles become soft references.
Design note
The use of a common cache for all images makes easier to set an application-wide limit (for example 25% of available memory). The use of soft reference does not cause as much memory retention as it may seem because those references are hold only as long as the image exist. When an image is garbage collected, the corresponding soft references are cleaned.- Since:
- 1.1
- Version:
- 1.3
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final class
A compound key identifying a tile of aComputedImage
.Nested classes/interfaces inherited from class org.apache.sis.util.collection.Cache
Cache.Handler<V>
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,
V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Methods inherited from class org.apache.sis.util.collection.Cache
clear, compute, computeIfAbsent, computeIfPresent, containsKey, entrySet, get, getOrCreate, isEmpty, isKeyCollisionAllowed, keySet, lock, merge, peek, put, putIfAbsent, remove, remove, replace, replace, replaceAll, setKeyCollisionAllowed, size
Methods inherited from class java.util.AbstractMap
clone, containsValue, equals, hashCode, putAll, toString, values
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.concurrent.ConcurrentMap
forEach, getOrDefault
-
Field Details
-
GLOBAL
The instance shared by all image operations. Current version does not allow to specify a custom cache for some images, but a future version may allow that.
-
-
Constructor Details
-
TileCache
private TileCache()Creates a new tile cache. We put an arbitrary limit of 25% of available memory. If more tiles are created, some strong references will become soft references. Because strong references may be kept by the JVM, the amount of memory actually used may be greater than this limit. However, those references are cleaned when the image owning those tiles is garbage collected.
-
-
Method Details
-
cost
Returns an estimation of the memory consumption of the given tile.- Overrides:
cost
in classCache<TileCache.Key,
Raster> - Parameters:
tile
- the tile for which to estimate memory usage.- Returns:
- memory used by the given tile, in bytes.
- See Also:
-
flush
public boolean flush()Forces the removal of all garbage collected tiles. This method should not need to be invoked. It is provided as a debugging tools when suspecting a memory leak.- Overrides:
flush
in classCache<TileCache.Key,
Raster> - Returns:
true
if some entries have been removed as a result of this method call.- See Also:
-