Class LRUMediaCache<V>


@NonNullByDefault public class LRUMediaCache<V> extends Object
Cache system for media files, and their metadata This is a LRU cache (least recently used entry is evicted if the size is exceeded). Size is based on the size on disk (in bytes)
Gwendal Roulleau - Initial contribution
  • Field Details

    • maxCacheSize

      protected final long maxCacheSize
      The size limit, in bytes. The size is not a hard one, because the final size of the current request is not known and may or may not exceed the limit.
    • cacheIsOK

      protected boolean cacheIsOK
  • Constructor Details

    • LRUMediaCache

      public LRUMediaCache(StorageService storageService, long maxCacheSize, String pid, @Nullable ClassLoader clazzLoader)
      Constructs a cache system.
      storageService - Storage service to store metadata
      maxCacheSize - Limit size, in byte
      pid - A pid identifying the cache on disk
  • Method Details

    • get

      public LRUMediaCacheEntry<V> get(String key, Supplier<LRUMediaCacheEntry<V>> supplier)
      Returns a LRUMediaCacheEntry from the cache, or if not already in the cache : resolve it, stores it, and returns it. key A unique key identifying the result supplier the data and metadata supplier. It is OK to launch a DataRetrievalException from this, as it will be rethrown.
    • put

      protected void put(LRUMediaCacheEntry<V> result)
    • makeSpace

      protected void makeSpace()
      Check if the cache is not already full and make space if needed. We don't use the removeEldestEntry test method from the linkedHashMap because it can only remove one element.