1
0
mirror of https://github.com/AuthMe/AuthMeReloaded.git synced 2024-12-30 04:27:50 +01:00

Added cache removal listener.

* Re-add auth object if player is still authenticated
This commit is contained in:
DNx5 2015-12-12 19:48:01 +07:00
parent efcdca4087
commit 973bfd2590

View File

@ -3,6 +3,9 @@ package fr.xephi.authme.datasource;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader; import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache; import com.google.common.cache.LoadingCache;
import com.google.common.cache.RemovalListener;
import com.google.common.cache.RemovalListeners;
import com.google.common.cache.RemovalNotification;
import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.auth.PlayerCache;
@ -30,6 +33,15 @@ public class CacheDataSource implements DataSource {
this.exec = Executors.newCachedThreadPool(); this.exec = Executors.newCachedThreadPool();
cachedAuths = CacheBuilder.newBuilder() cachedAuths = CacheBuilder.newBuilder()
.expireAfterWrite(5, TimeUnit.MINUTES) .expireAfterWrite(5, TimeUnit.MINUTES)
.removalListener(RemovalListeners.asynchronous(new RemovalListener<String, PlayerAuth>() {
@Override
public void onRemoval(RemovalNotification<String, PlayerAuth> removalNotification) {
String name = removalNotification.getKey();
if (PlayerCache.getInstance().isAuthenticated(name)) {
cachedAuths.getUnchecked(name);
}
}
}, exec))
.build( .build(
new CacheLoader<String, PlayerAuth>() { new CacheLoader<String, PlayerAuth>() {
public PlayerAuth load(String key) { public PlayerAuth load(String key) {