Class LRUMediaCache<V>

java.lang.Object
org.openhab.core.cache.lru.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)
Author:
Gwendal Roulleau - Initial contribution
  • Field Details Link icon

    • maxCacheSize Link icon

      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 Link icon

      protected boolean cacheIsOK
  • Constructor Details Link icon

    • LRUMediaCache Link icon

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

    • get Link icon

      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 Link icon

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

      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.