mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-12 15:56:00 +08:00
Adds the removal of the cached player pages on analysis
This commit is contained in:
parent
ad2a3d80ae
commit
659bc8d1db
@ -4,6 +4,9 @@ import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import main.java.com.djrapitops.plan.ui.webserver.response.Response;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* This class contains the page cache.
|
||||
* <p>
|
||||
@ -77,10 +80,25 @@ public class PageCacheHandler {
|
||||
return pageCache.asMap().containsKey(identifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all of the elements of this cache that satisfy the given predicate.
|
||||
*
|
||||
* @param filter a predicate which returns true for entries to be removed
|
||||
*/
|
||||
public static void removeIf(Predicate<String> filter) {
|
||||
Map<String, Response> pageCacheMap = pageCache.asMap();
|
||||
|
||||
for (String identifier : pageCacheMap.keySet()) {
|
||||
if (filter.test(identifier)) {
|
||||
pageCache.invalidate(identifier);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the cache from all its contents.
|
||||
*/
|
||||
public static void clearCache() {
|
||||
pageCache.asMap().clear();
|
||||
pageCache.invalidateAll();
|
||||
}
|
||||
}
|
||||
|
@ -165,8 +165,10 @@ public class Analysis {
|
||||
Log.info(Locale.get(Msg.ANALYSIS_FINISHED).parse(String.valueOf(time), HtmlUtils.getServerAnalysisUrlWithProtocol()));
|
||||
}
|
||||
|
||||
PageCacheHandler.removeIf(identifier -> identifier.startsWith("inspectPage: "));
|
||||
PageCacheHandler.cachePage("analysisPage", () -> new AnalysisPageResponse(plugin.getUiServer().getDataReqHandler()));
|
||||
PageCacheHandler.cachePage("players", () -> new PlayersPageResponse(plugin));
|
||||
|
||||
ExportUtility.export(analysisData, rawData);
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
|
@ -50,4 +50,13 @@ public class PageCacheHandlerTest {
|
||||
PageCacheHandler.clearCache();
|
||||
assertFalse(PageCacheHandler.isCached(IDENTIFIER));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveIf() {
|
||||
PageCacheHandler.cachePage(IDENTIFIER, LOADER);
|
||||
assertTrue(PageCacheHandler.isCached(IDENTIFIER));
|
||||
|
||||
PageCacheHandler.removeIf(identifier -> identifier.equals(IDENTIFIER));
|
||||
assertFalse(PageCacheHandler.isCached(IDENTIFIER));
|
||||
}
|
||||
}
|
||||
|
@ -36,18 +36,12 @@ public class SessionCacheTest {
|
||||
public SessionCacheTest() {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
TestInit.init();
|
||||
test = new SessionCache();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testStartSession() {
|
||||
UUID uuid = MockUtils.getPlayerUUID();
|
||||
@ -55,9 +49,6 @@ public class SessionCacheTest {
|
||||
assertTrue("Didn't contain new session", test.getActiveSessions().containsKey(uuid));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testEndSession() {
|
||||
UUID uuid = MockUtils.getPlayerUUID();
|
||||
@ -69,9 +60,6 @@ public class SessionCacheTest {
|
||||
assertTrue("Session not valid", testSession.isValid());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testAddSession() {
|
||||
UUID uuid = MockUtils.getPlayerUUID();
|
||||
|
Loading…
Reference in New Issue
Block a user