Package org.openhab.core.cache.lru
Class LRUMediaCache<V>
java.lang.Object
org.openhab.core.cache.lru.LRUMediaCache<V>
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 Summary
Modifier and TypeFieldDescriptionprotected boolean
protected final long
The size limit, in bytes. -
Constructor Summary
ConstructorDescriptionLRUMediaCache
(StorageService storageService, long maxCacheSize, String pid, @Nullable ClassLoader clazzLoader) Constructs a cache system. -
Method Summary
Modifier and TypeMethodDescriptionget
(String key, Supplier<LRUMediaCacheEntry<V>> supplier) Returns aLRUMediaCacheEntry
from the cache, or if not already in the cache : resolve it, stores it, and returns it.protected void
Check if the cache is not already full and make space if needed.protected void
put
(LRUMediaCacheEntry<V> result)
-
Field Details
-
maxCacheSize
protected final long maxCacheSizeThe 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.- Parameters:
storageService
- Storage service to store metadatamaxCacheSize
- Limit size, in bytepid
- A pid identifying the cache on disk
-
-
Method Details
-
get
Returns aLRUMediaCacheEntry
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
-
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.
-