Package io.github.xanthic.cache.core
Class LockedAbstractCache<K,V>
java.lang.Object
io.github.xanthic.cache.core.LockedAbstractCache<K,V>
- Type Parameters:
K- The type of keys that form the cacheV- The type of values contained in the cache
- All Implemented Interfaces:
io.github.xanthic.cache.api.Cache<K,V>
public abstract class LockedAbstractCache<K,V>
extends java.lang.Object
implements io.github.xanthic.cache.api.Cache<K,V>
Safely implements
Cache methods using ReadWriteLock.
This abstraction allows for underlying cache providers to implement
the Cache interface in a thread-safe manner, even if the
underlying cache does not already implement the more "exotic"
write methods required by the Cache contract.
As this abstraction has a performance hit, it should be avoided if the backing cache provider already provides an implementation for these methods.
Does not support null values.
-
Field Summary
Fields Modifier and Type Field Description protected java.util.concurrent.locks.ReadWriteLocklock -
Constructor Summary
Constructors Constructor Description LockedAbstractCache() -
Method Summary
Modifier and Type Method Description voidclear()protected abstract voidclearUnlocked()Vcompute(K key, @NotNull java.util.function.BiFunction<? super K,? super V,? extends V> computeFunc)VcomputeIfAbsent(K key, @NotNull java.util.function.Function<K,V> computeFunc)VcomputeIfPresent(K key, @NotNull java.util.function.BiFunction<? super K,? super V,? extends V> computeFunc)Vget(K key)protected abstract VgetUnlocked(K key)Vmerge(K key, V value, @NotNull java.util.function.BiFunction<V,V,V> mergeFunc)Vput(K key, V value)voidputAll(@NotNull java.util.Map<? extends K,? extends V> map)VputIfAbsent(K key, V value)protected abstract voidputUnlocked(K key, V value)protected <T> Tread(java.util.function.Supplier<T> reader)Vremove(K key)protected abstract voidremoveUnlocked(K key)booleanreplace(K key, V value)booleanreplace(K key, V oldValue, V newValue)longsize()protected abstract longsizeUnlocked()protected <T> Twrite(java.util.function.Supplier<T> writer)
-
Field Details
-
lock
protected final java.util.concurrent.locks.ReadWriteLock lock
-
-
Constructor Details
-
LockedAbstractCache
public LockedAbstractCache()
-
-
Method Details
-
get
-
put
-
remove
-
clear
public void clear() -
size
public long size() -
compute
-
computeIfAbsent
-
computeIfPresent
-
putIfAbsent
-
merge
-
replace
-
replace
-
putAll
-
getUnlocked
-
putUnlocked
-
removeUnlocked
-
clearUnlocked
protected abstract void clearUnlocked() -
sizeUnlocked
protected abstract long sizeUnlocked() -
read
protected <T> T read(java.util.function.Supplier<T> reader) -
write
protected <T> T write(java.util.function.Supplier<T> writer)
-