TerraForged/TerraForgedCore/src/main/java/com/terraforged/core/util/concurrent/cache/CacheEntry.java
dags- eea88bd0e2 - improved performance of chunk-gen operations
- optimized caching for heightmap & rivermap regions
- hopefully fixed some deadlock issues
- reverted custom mushrooms for now
2020-03-18 18:12:50 +00:00

38 lines
991 B
Java

package com.terraforged.core.util.concurrent.cache;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletionException;
import java.util.concurrent.Executor;
import java.util.concurrent.FutureTask;
public class CacheEntry<T> extends FutureTask<T> implements ExpiringEntry {
private volatile long timestamp;
private CacheEntry(Callable<T> supplier) {
super(supplier);
this.timestamp = System.currentTimeMillis();
}
@Override
public long getTimestamp() {
return timestamp;
}
@Override
public T get() {
try {
this.timestamp = System.currentTimeMillis();
return super.get();
} catch (Throwable t) {
throw new CompletionException(t);
}
}
public static <T> CacheEntry<T> supplyAsync(Callable<T> supplier, Executor executor) {
CacheEntry<T> entry = new CacheEntry<>(supplier);
executor.execute(entry);
return entry;
}
}