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