Better server caching.

This commit is contained in:
Tux 2014-08-09 23:57:57 -04:00
parent d3b2f3f10b
commit 6df0a481e7
2 changed files with 12 additions and 7 deletions

View File

@ -22,7 +22,6 @@ import redis.clients.jedis.exceptions.JedisConnectionException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
/**
@ -40,7 +39,6 @@ public class DataManager implements Listener {
* Most of these are purged only based on size limits but are also invalidated on certain actions.
*/
private final Cache<UUID, String> serverCache = CacheBuilder.newBuilder()
.expireAfterWrite(5, TimeUnit.SECONDS)
.maximumSize(2000)
.concurrencyLevel(2)
.build();
@ -244,8 +242,12 @@ public class DataManager implements Listener {
if (message.getSource().equals(source))
return;
// For now we will just invalidate the caches. In a future version the action scope will be expanded ;)
invalidate(message.getTarget());
// For now we will just invalidate the caches, depending on what action occurred.
if (message.getAction() == DataManagerMessage.Action.SERVER_CHANGE) {
serverCache.invalidate(message.getTarget());
} else {
invalidate(message.getTarget());
}
}
@Getter
@ -253,7 +255,8 @@ public class DataManager implements Listener {
static class DataManagerMessage {
enum Action {
JOIN,
LEAVE
LEAVE,
SERVER_CHANGE
}
private final UUID target;

View File

@ -64,8 +64,10 @@ public class RedisBungeeConsumer implements Runnable {
pipeline.sync();
} else if (event instanceof PlayerChangedServerConsumerEvent) {
PlayerChangedServerConsumerEvent event1 = (PlayerChangedServerConsumerEvent) event;
// No use in pipelining this
jedis.hset("player:" + event1.getPlayer().getUniqueId().toString(), "server", event1.getNewServer().getName());
Pipeline pipeline = jedis.pipelined();
pipeline.hset("player:" + event1.getPlayer().getUniqueId().toString(), "server", event1.getNewServer().getName());
pipeline.publish("redisbungee-data", RedisBungee.getGson().toJson(new DataManager.DataManagerMessage(event1.getPlayer().getUniqueId(), DataManager.DataManagerMessage.Action.SERVER_CHANGE)));
pipeline.sync();
}
}