Interface GranuleImageCache
- All Known Implementing Classes:
GuavaGranuleImageCache
ImageMosaicReaders can reuse across requests,
sized by total decoded bytes with LRU eviction. Built and owned by the caller, injected into readers at construction
time through Hints.GRANULE_IMAGE_CACHE and enabled via the
ImageMosaicFormat.CACHE_GRANULES read parameter. Implementations must be thread-safe.
Entries are keyed by owning mosaic plus granule URL, image index and band selection, so the pool can shed a
mosaic's whole footprint at once through invalidateMosaic(String) when its reader is disposed (store reload,
remove or reset): heap then tracks the mosaic's lifecycle instead of lingering until the LRU bound reclaims it. A
stale single granule (an in-place overwrite, a re-harvest, a delete) is dropped with invalidateGranule(URL),
and invalidateAll() clears the pool. The band selection is part of the key because it's typically associated
with multispectral/hyperspectral images where there are too many bands to cache the whole set.
A cached BufferedImage is shared, as-is, by every request that hits it, so the read path must treat it strictly read-only: no consumer may write into its raster in place, or it would corrupt other requests' and other mosaics' reads.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classThrown by agetOrLoad(org.geotools.gce.imagemosaic.ImageCacheKey, java.util.concurrent.Callable<java.awt.image.BufferedImage>)loader to signal the read produced nothing;getOrLoad(org.geotools.gce.imagemosaic.ImageCacheKey, java.util.concurrent.Callable<java.awt.image.BufferedImage>)maps it to anullresult instead of caching. -
Method Summary
Modifier and TypeMethodDescriptionget(ImageCacheKey key) Returns the cached image for the key, ornullon a miss; never loads.longLargest decoded granule eligible for caching, in bytes (a read parameter can override it).longMaximum size of the pool, in bytes.getOrLoad(ImageCacheKey key, Callable<BufferedImage> loader) Returns the cached image for the key, loading it once atomically if absent.voidDrops all cached granule images.voidinvalidateGranule(URL granuleUrl) Drops every cached read of the given granule, whatever the mosaic, image index or band selection.voidinvalidateMosaic(String mosaicId) Drops every entry owned by the given mosaic, called when its reader is disposed to free heap at once.booleanWhether caching is on: a non-positive max size means the pool is present but denies caching.voidreconfigure(long maximumSizeBytes, long defaultThresholdBytes) Applies new sizing while keeping this instance's identity, so readers holding it throughHints.GRANULE_IMAGE_CACHEsee the change with no rebuild on their side.longsize()Number of granule images currently held.
-
Method Details
-
reconfigure
void reconfigure(long maximumSizeBytes, long defaultThresholdBytes) Applies new sizing while keeping this instance's identity, so readers holding it throughHints.GRANULE_IMAGE_CACHEsee the change with no rebuild on their side. A change in total size may drop the current entries and free their heap at once; the threshold is applied in place. -
isEnabled
boolean isEnabled()Whether caching is on: a non-positive max size means the pool is present but denies caching. -
size
long size()Number of granule images currently held. -
invalidateAll
void invalidateAll()Drops all cached granule images. -
invalidateGranule
Drops every cached read of the given granule, whatever the mosaic, image index or band selection. -
invalidateMosaic
Drops every entry owned by the given mosaic, called when its reader is disposed to free heap at once. -
getMaximumSizeBytes
long getMaximumSizeBytes()Maximum size of the pool, in bytes. -
getDefaultThresholdBytes
long getDefaultThresholdBytes()Largest decoded granule eligible for caching, in bytes (a read parameter can override it). -
get
Returns the cached image for the key, ornullon a miss; never loads. -
getOrLoad
Returns the cached image for the key, loading it once atomically if absent. Returnsnullif the loader signals nothing was read by throwingGranuleImageCache.MissingRasterException; any other loader failure propagates.- Throws:
Exception
-