From 973bfd2590485ce22bf45c4f91f31a37c300119c Mon Sep 17 00:00:00 2001 From: DNx5 Date: Sat, 12 Dec 2015 19:48:01 +0700 Subject: [PATCH] Added cache removal listener. * Re-add auth object if player is still authenticated --- .../fr/xephi/authme/datasource/CacheDataSource.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java index a1f74dd37..2d12a720a 100644 --- a/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java +++ b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java @@ -3,6 +3,9 @@ package fr.xephi.authme.datasource; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; 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.PlayerCache; @@ -30,6 +33,15 @@ public class CacheDataSource implements DataSource { this.exec = Executors.newCachedThreadPool(); cachedAuths = CacheBuilder.newBuilder() .expireAfterWrite(5, TimeUnit.MINUTES) + .removalListener(RemovalListeners.asynchronous(new RemovalListener() { + @Override + public void onRemoval(RemovalNotification removalNotification) { + String name = removalNotification.getKey(); + if (PlayerCache.getInstance().isAuthenticated(name)) { + cachedAuths.getUnchecked(name); + } + } + }, exec)) .build( new CacheLoader() { public PlayerAuth load(String key) {