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 com.google.common.cache.CacheBuilder;
|
||||||
import main.java.com.djrapitops.plan.ui.webserver.response.Response;
|
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.
|
* This class contains the page cache.
|
||||||
* <p>
|
* <p>
|
||||||
@ -77,10 +80,25 @@ public class PageCacheHandler {
|
|||||||
return pageCache.asMap().containsKey(identifier);
|
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.
|
* Clears the cache from all its contents.
|
||||||
*/
|
*/
|
||||||
public static void clearCache() {
|
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()));
|
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("analysisPage", () -> new AnalysisPageResponse(plugin.getUiServer().getDataReqHandler()));
|
||||||
PageCacheHandler.cachePage("players", () -> new PlayersPageResponse(plugin));
|
PageCacheHandler.cachePage("players", () -> new PlayersPageResponse(plugin));
|
||||||
|
|
||||||
ExportUtility.export(analysisData, rawData);
|
ExportUtility.export(analysisData, rawData);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.toLog(this.getClass().getName(), e);
|
Log.toLog(this.getClass().getName(), e);
|
||||||
|
@ -50,4 +50,13 @@ public class PageCacheHandlerTest {
|
|||||||
PageCacheHandler.clearCache();
|
PageCacheHandler.clearCache();
|
||||||
assertFalse(PageCacheHandler.isCached(IDENTIFIER));
|
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() {
|
public SessionCacheTest() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
TestInit.init();
|
TestInit.init();
|
||||||
test = new SessionCache();
|
test = new SessionCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Test
|
@Test
|
||||||
public void testStartSession() {
|
public void testStartSession() {
|
||||||
UUID uuid = MockUtils.getPlayerUUID();
|
UUID uuid = MockUtils.getPlayerUUID();
|
||||||
@ -55,9 +49,6 @@ public class SessionCacheTest {
|
|||||||
assertTrue("Didn't contain new session", test.getActiveSessions().containsKey(uuid));
|
assertTrue("Didn't contain new session", test.getActiveSessions().containsKey(uuid));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Test
|
@Test
|
||||||
public void testEndSession() {
|
public void testEndSession() {
|
||||||
UUID uuid = MockUtils.getPlayerUUID();
|
UUID uuid = MockUtils.getPlayerUUID();
|
||||||
@ -69,9 +60,6 @@ public class SessionCacheTest {
|
|||||||
assertTrue("Session not valid", testSession.isValid());
|
assertTrue("Session not valid", testSession.isValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddSession() {
|
public void testAddSession() {
|
||||||
UUID uuid = MockUtils.getPlayerUUID();
|
UUID uuid = MockUtils.getPlayerUUID();
|
||||||
|
Loading…
Reference in New Issue
Block a user