mirror of https://github.com/Minestom/Minestom.git
Replace guava cache to caffeine
This commit is contained in:
parent
c90bae063a
commit
e635e29a16
|
@ -138,6 +138,8 @@ dependencies {
|
|||
// https://search.maven.org/artifact/org.fusesource.jansi/jansi/2.3.2/jar
|
||||
implementation 'org.fusesource.jansi:jansi:2.3.2'
|
||||
|
||||
implementation 'com.github.ben-manes.caffeine:caffeine:3.0.2'
|
||||
|
||||
// Guava 21.0+ required for Mixin
|
||||
api 'com.google.guava:guava:30.1-jre'
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package net.minestom.server.command.builder;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectRBTreeMap;
|
||||
import net.minestom.server.command.CommandSender;
|
||||
import net.minestom.server.command.builder.arguments.Argument;
|
||||
|
@ -25,7 +25,7 @@ public class CommandDispatcher {
|
|||
private final Map<String, Command> commandMap = new HashMap<>();
|
||||
private final Set<Command> commands = new HashSet<>();
|
||||
|
||||
private final Cache<String, CommandResult> cache = CacheBuilder.newBuilder()
|
||||
private final Cache<String, CommandResult> cache = Caffeine.newBuilder()
|
||||
.expireAfterWrite(30, TimeUnit.SECONDS)
|
||||
.build();
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package net.minestom.server.utils.cache;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.RemovalListener;
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.github.benmanes.caffeine.cache.RemovalListener;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
@ -24,7 +24,7 @@ public class TemporaryCache<T> {
|
|||
* @param duration the time before considering an object unused
|
||||
*/
|
||||
public TemporaryCache(long duration, TimeUnit timeUnit, RemovalListener<UUID, T> removalListener) {
|
||||
this.cache = CacheBuilder.newBuilder()
|
||||
this.cache = Caffeine.newBuilder()
|
||||
.expireAfterWrite(duration, timeUnit)
|
||||
.removalListener(removalListener)
|
||||
.build();
|
||||
|
|
|
@ -6,8 +6,10 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
public class TemporaryPacketCache extends TemporaryCache<TimedBuffer> {
|
||||
public TemporaryPacketCache(long duration, TimeUnit timeUnit) {
|
||||
super(duration, timeUnit, notification -> {
|
||||
final ByteBuf buffer = notification.getValue().getBuffer();
|
||||
super(duration, timeUnit, (key, value, cause) -> {
|
||||
if (value == null)
|
||||
return;
|
||||
final ByteBuf buffer = value.getBuffer();
|
||||
synchronized (buffer) {
|
||||
buffer.release();
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package net.minestom.server.utils.mojang;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
|
@ -17,12 +17,12 @@ import java.util.concurrent.TimeUnit;
|
|||
*/
|
||||
public final class MojangUtils {
|
||||
|
||||
private static final Cache<String, JsonObject> UUID_CACHE = CacheBuilder.newBuilder()
|
||||
private static final Cache<String, JsonObject> UUID_CACHE = Caffeine.newBuilder()
|
||||
.expireAfterWrite(30, TimeUnit.SECONDS)
|
||||
.softValues()
|
||||
.build();
|
||||
|
||||
private static final Cache<String, JsonObject> USERNAME_CACHE = CacheBuilder.newBuilder()
|
||||
private static final Cache<String, JsonObject> USERNAME_CACHE = Caffeine.newBuilder()
|
||||
.expireAfterWrite(30, TimeUnit.SECONDS)
|
||||
.softValues()
|
||||
.build();
|
||||
|
|
Loading…
Reference in New Issue