Class CacheUtils

java.lang.Object
com.arbergashi.charts.util.CacheUtils

public final class CacheUtils extends Object
Utility for bounded LRU caches.

This prevents memory leaks caused by unbounded caches in long-running applications.

Since:
2026-01-01
Version:
1.0.0
Author:
Arber Gashi
  • Method Details

    • newBoundedMap

      public static <K,V> Map<K,V> newBoundedMap(int maxEntries)
      Creates a bounded LRU cache with a fixed maximum size.

      Uses LinkedHashMap for automatic eviction of the eldest entry.

      Type Parameters:
      K - key type
      V - value type
      Parameters:
      maxEntries - maximum number of entries (e.g. 64 for gradient caches)
      Returns:
      a map instance with LRU behavior