mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 10:12:53 +00:00
No cache locks
This commit is contained in:
parent
08e2244975
commit
56723330b3
@ -19,6 +19,7 @@
|
||||
package com.volmit.iris.core.pregenerator;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.gui.PregeneratorJob;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.collection.KSet;
|
||||
|
@ -27,20 +27,25 @@ import java.util.function.Function;
|
||||
|
||||
public class KCache<K,V> implements MeteredCache {
|
||||
private long max;
|
||||
private CacheLoader<? super K, ? extends V> loader;
|
||||
private CacheLoader<K, V> loader;
|
||||
private LoadingCache<K, V> cache;
|
||||
|
||||
public KCache(CacheLoader<K, V> loader, long max)
|
||||
{
|
||||
this.max = max;
|
||||
this.loader = loader;
|
||||
this.cache = Caffeine
|
||||
this.cache = create(loader);
|
||||
}
|
||||
|
||||
private LoadingCache<K,V> create(CacheLoader<K,V> loader) {
|
||||
return Caffeine
|
||||
.newBuilder()
|
||||
.maximumSize(max)
|
||||
.build((k) -> loader == null ? null : loader.load(k));
|
||||
}
|
||||
|
||||
public void setLoader(CacheLoader<? super K, ? extends V> loader)
|
||||
|
||||
public void setLoader(CacheLoader<K, V> loader)
|
||||
{
|
||||
this.loader = loader;
|
||||
}
|
||||
@ -52,8 +57,9 @@ public class KCache<K,V> implements MeteredCache {
|
||||
|
||||
public void invalidate()
|
||||
{
|
||||
cache.invalidateAll();
|
||||
cache.cleanUp();
|
||||
LoadingCache<?,?> c = cache;
|
||||
cache = create(loader);
|
||||
c.invalidateAll();
|
||||
}
|
||||
|
||||
public V get(K k)
|
||||
|
Loading…
x
Reference in New Issue
Block a user