Class ImageCache
java.lang.Object
com.norconex.crawler.web.doc.operations.image.impl.ImageCache
Thread-safe, in-memory LRU cache for featured images, keyed by image URL. Prevents re-downloading and re-scaling the same image when it appears on multiple crawled pages (e.g., a shared logo or banner).
Images are stored as PNG-compressed byte arrays rather than
raw BufferedImage objects, reducing per-entry memory by
roughly 10–50× (e.g., a 200×200 scaled image
uses ~5–10 KB compressed vs ~160 KB raw).
The cache is local to each crawler node — it is intentionally not shared across cluster nodes because serializing image payloads through the grid would negate the performance benefit.
- Since:
- 2.8.0
-
Constructor Summary
ConstructorsConstructorDescriptionImageCache(int maxSize) Creates a new in-memory image cache with the given maximum number of entries. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the number of images currently in the cache.Returns the cached image for the given URL, ornullif absent or if the cached entry cannot be decoded.voidsetImage(FeaturedImage image) Stores a featured image in the cache as a PNG-compressed byte array, keyed by its URL.
-
Constructor Details
-
ImageCache
public ImageCache(int maxSize) Creates a new in-memory image cache with the given maximum number of entries.- Parameters:
maxSize- maximum cached images before the least-recently used entry is evicted
-
-
Method Details
-
getImage
Returns the cached image for the given URL, ornullif absent or if the cached entry cannot be decoded.- Parameters:
url- image URL- Returns:
- cached image or
null
-
setImage
Stores a featured image in the cache as a PNG-compressed byte array, keyed by its URL.- Parameters:
image- the featured image to cache
-
getCacheSize
public int getCacheSize()Returns the number of images currently in the cache.- Returns:
- current cache size
-