No cache locks

This commit is contained in:
cyberpwn 2021-09-23 04:32:49 -04:00
parent 08e2244975
commit 56723330b3
2 changed files with 12 additions and 5 deletions

View File

@ -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;

View File

@ -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)