Package tigase.pubsub.utils
Class LRUCache<K,V>
java.lang.Object
tigase.pubsub.utils.LRUCache<K,V>
- Type Parameters:
K-V-
- All Implemented Interfaces:
Cache<K,,V> tigase.stats.StatisticHolder
This class is implementation of
Cache interface. The main difference between LRUCache and
LRUCacheWithFuture is LRUCache implementation of
computeIfAbsent(K key, CacheSupplier).
In case when there is no value, LRUCache executes provided instance of CacheSupplier in
a synchronized block resulting in blocking of all access to the cache while result to "put" in being generated.
On the other hand, LRUCacheWithFuture, when there is no result, puts instance of
a CompletableFuture in the cache (instance of LRUCache) as a value and then waits for
the completion of the CacheSupplier to return the value. In this implementation, long process of
generating value by CacheSupplier is not blocking access to the cache for other "keys". Parallel
requests to get value for the same key will be "lock" and CacheSupplier will be called only once
if the value is not in the cache.-
Nested Class Summary
Nested classes/interfaces inherited from interface tigase.pubsub.utils.Cache
Cache.CacheException, Cache.CacheSupplier<V> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncomputeIfAbsent(K key, Cache.CacheSupplier<V> supplier) voidvoidvoidvoidgetStatistics(String compName, tigase.stats.StatisticsList list) keySet()putIfAbsent(K key, V value) booleanvoidsetMaxSize(int size) voidsetStatisticsPrefix(String prefix) intsize()voidstatisticExecutedIn(long executionTime) values()
-
Constructor Details
-
LRUCache
public LRUCache() -
LRUCache
public LRUCache(int maxSize)
-
-
Method Details
-
computeIfAbsent
- Specified by:
computeIfAbsentin interfaceCache<K,V> - Throws:
Cache.CacheException
-
get
-
put
-
putIfAbsent
- Specified by:
putIfAbsentin interfaceCache<K,V>
-
remove
-
remove
-
keySet
-
values
-
size
public int size() -
setMaxSize
public void setMaxSize(int size) - Specified by:
setMaxSizein interfaceCache<K,V>
-
everyHour
public void everyHour()- Specified by:
everyHourin interfacetigase.stats.StatisticHolder
-
everyMinute
public void everyMinute()- Specified by:
everyMinutein interfacetigase.stats.StatisticHolder
-
everySecond
public void everySecond()- Specified by:
everySecondin interfacetigase.stats.StatisticHolder
-
getStatistics
- Specified by:
getStatisticsin interfacetigase.stats.StatisticHolder
-
setStatisticsPrefix
- Specified by:
setStatisticsPrefixin interfacetigase.stats.StatisticHolder
-
statisticExecutedIn
public void statisticExecutedIn(long executionTime) - Specified by:
statisticExecutedInin interfacetigase.stats.StatisticHolder
-