9
0
mirror of https://github.com/VolmitSoftware/Iris.git synced 2025-12-27 19:19:07 +00:00

DANGER V+

This commit is contained in:
cyberpwn
2021-09-25 13:37:54 -04:00
parent 333e158ca5
commit bee920f96a
11 changed files with 65 additions and 37 deletions

View File

@@ -21,19 +21,15 @@ package com.volmit.iris.util.data;
import com.github.benmanes.caffeine.cache.CacheLoader;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache;
import com.volmit.iris.Iris;
import com.volmit.iris.engine.framework.MeteredCache;
import com.volmit.iris.util.format.Form;
import com.volmit.iris.util.scheduling.J;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import com.volmit.iris.util.math.RollingSequence;
public class KCache<K,V> implements MeteredCache {
private final long max;
private CacheLoader<K, V> loader;
private LoadingCache<K, V> cache;
private final boolean fastDump;
private final RollingSequence msu = new RollingSequence(100);
public KCache(CacheLoader<K, V> loader, long max)
{
@@ -52,9 +48,8 @@ public class KCache<K,V> implements MeteredCache {
return Caffeine
.newBuilder()
.maximumSize(max)
.initialCapacity((int) (max))
.softValues()
.expireAfterAccess(5, TimeUnit.MINUTES)
.initialCapacity((int) (max))
.build((k) -> loader == null ? null : loader.load(k));
}
@@ -84,6 +79,11 @@ public class KCache<K,V> implements MeteredCache {
return cache.estimatedSize();
}
@Override
public KCache<?, ?> getRawCache() {
return this;
}
@Override
public long getMaxSize() {
return max;

View File

@@ -289,12 +289,12 @@ public interface ProceduralStream<T> extends ProceduralLayer, Interpolated<T> {
return new To3DStream<T>(this);
}
default ProceduralStream<T> cache2D(Engine engine, int size) {
return new CachedStream2D<T>(engine, this, size);
default ProceduralStream<T> cache2D(String name, Engine engine, int size) {
return new CachedStream2D<T>(name, engine, this, size);
}
default ProceduralStream<T> cache3D(Engine engine, int maxSize) {
return new CachedStream3D<T>(engine, this, maxSize);
default ProceduralStream<T> cache3D(String name, Engine engine, int maxSize) {
return new CachedStream3D<T>(name, engine, this, maxSize);
}
default <V> ProceduralStream<V> convert(Function<T, V> converter) {

View File

@@ -37,7 +37,7 @@ public class CachedStream2D<T> extends BasicStream<T> implements ProceduralStrea
private final KCache<Long, T> cache;
private final Engine engine;
public CachedStream2D(Engine engine, ProceduralStream<T> stream, int size) {
public CachedStream2D(String name, Engine engine, ProceduralStream<T> stream, int size) {
super();
this.stream = stream;
this.engine = engine;
@@ -70,6 +70,11 @@ public class CachedStream2D<T> extends BasicStream<T> implements ProceduralStrea
return cache.getSize();
}
@Override
public KCache<?, ?> getRawCache() {
return cache;
}
@Override
public long getMaxSize() {
return cache.getMaxSize();

View File

@@ -32,7 +32,7 @@ public class CachedStream3D<T> extends BasicStream<T> implements ProceduralStrea
private final KCache<BlockPosition, T> cache;
private final Engine engine;
public CachedStream3D(Engine engine, ProceduralStream<T> stream, int size) {
public CachedStream3D(String name, Engine engine, ProceduralStream<T> stream, int size) {
super();
this.stream = stream;
this.engine = engine;
@@ -65,6 +65,11 @@ public class CachedStream3D<T> extends BasicStream<T> implements ProceduralStrea
return cache.getSize();
}
@Override
public KCache<?, ?> getRawCache() {
return cache;
}
@Override
public long getMaxSize() {
return cache.getMaxSize();