java.lang.Object
com.norconex.crawler.web.doc.operations.image.impl.ImageCache

public class ImageCache extends Object

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

    Constructors
    Constructor
    Description
    ImageCache(int maxSize)
    Creates a new in-memory image cache with the given maximum number of entries.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the number of images currently in the cache.
    Returns the cached image for the given URL, or null if absent or if the cached entry cannot be decoded.
    void
    Stores a featured image in the cache as a PNG-compressed byte array, keyed by its URL.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public FeaturedImage getImage(String url)
      Returns the cached image for the given URL, or null if absent or if the cached entry cannot be decoded.
      Parameters:
      url - image URL
      Returns:
      cached image or null
    • setImage

      public void setImage(FeaturedImage image)
      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