Package tigase.pubsub.utils
Class LRUCacheWithFuture<K,V>
java.lang.Object
tigase.pubsub.utils.LRUCacheWithFuture<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
-
Method Summary
Modifier and TypeMethodDescriptioncomputeIfAbsent
(K key, Cache.CacheSupplier<V> supplier) void
void
void
void
getStatistics
(String compName, tigase.stats.StatisticsList list) keySet()
putIfAbsent
(K key, V value) void
setMaxSize
(int size) void
setStatisticsPrefix
(String prefix) int
size()
void
statisticExecutedIn
(long executionTime) values()
-
Constructor Details
-
LRUCacheWithFuture
public LRUCacheWithFuture() -
LRUCacheWithFuture
public LRUCacheWithFuture(int maxSize)
-
-
Method Details
-
computeIfAbsent
- Specified by:
computeIfAbsent
in interfaceCache<K,
V> - Throws:
Cache.CacheException
-
get
-
put
-
putIfAbsent
- Specified by:
putIfAbsent
in interfaceCache<K,
V>
-
remove
-
keySet
-
values
-
size
public int size() -
setMaxSize
public void setMaxSize(int size) - Specified by:
setMaxSize
in interfaceCache<K,
V>
-
everyHour
public void everyHour()- Specified by:
everyHour
in interfacetigase.stats.StatisticHolder
-
everyMinute
public void everyMinute()- Specified by:
everyMinute
in interfacetigase.stats.StatisticHolder
-
everySecond
public void everySecond()- Specified by:
everySecond
in interfacetigase.stats.StatisticHolder
-
getStatistics
- Specified by:
getStatistics
in interfacetigase.stats.StatisticHolder
-
setStatisticsPrefix
- Specified by:
setStatisticsPrefix
in interfacetigase.stats.StatisticHolder
-
statisticExecutedIn
public void statisticExecutedIn(long executionTime) - Specified by:
statisticExecutedIn
in interfacetigase.stats.StatisticHolder
-