-
-
Save willies952002/0a598523694ad07184f1de4e1a3f0940 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static final RemovalListener<Object, EmpireUser> USER_REMOVAL_LISTENER = notification -> { | |
final EmpireUser user = notification.getValue(); | |
switch (notification.getCause()) { | |
case EXPIRED: | |
case SIZE: | |
if (user != null && user.getPlayer() != null && user.getPlayer().isOnline()) { | |
user.refreshCaches(); | |
} | |
} | |
}; | |
public static Cache<UUID, String> uuidToNameCache = | |
CacheBuilder.newBuilder() | |
.maximumSize(100) | |
.expireAfterAccess(3, TimeUnit.DAYS) | |
.build(); | |
public static Cache<UUID, EmpireUser> EmpireUser_uuidCache = | |
CacheBuilder.newBuilder() | |
.maximumSize(512) | |
.expireAfterAccess(15, TimeUnit.MINUTES) | |
.removalListener(USER_REMOVAL_LISTENER) | |
.build(); | |
public static Cache<String, EmpireUser> EmpireUser_nameCache = | |
CacheBuilder.newBuilder() | |
.maximumSize(1024) | |
.expireAfterAccess(30, TimeUnit.MINUTES) | |
.removalListener(USER_REMOVAL_LISTENER) | |
.build(); | |
public static Cache<Long, EmpireUser> EmpireUser_userIdCache = | |
CacheBuilder.newBuilder() | |
.maximumSize(1024) | |
.expireAfterAccess(30, TimeUnit.MINUTES) | |
.removalListener(USER_REMOVAL_LISTENER) | |
.build(); | |
public static LoadingCache<Long, Boolean> bannedCache = | |
CacheBuilder.newBuilder() | |
.maximumSize(100) | |
.expireAfterWrite(5, TimeUnit.MINUTES) | |
.build(new CacheLoader<Long, Boolean>() { | |
@Override | |
public Boolean load(Long user) throws Exception { | |
try { | |
return EmpireDb.getFirstRow( | |
"SELECT user_id FROM user_ban WHERE user_id = ?", user) != null; | |
} catch (SQLException e) { | |
Util.printException( | |
"Exception in isBanned: " + user, e); | |
} | |
return false; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment