From df19b3b7329dbf7cfb831148423feca9498ea67e Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Mon, 12 Aug 2024 17:32:50 +0200 Subject: [PATCH] Added a html cache feature. --- .../statoolinfosweb/CrawlCacheChecker.java | 2 +- .../statoolinfosweb/StatoolInfosWeb.java | 20 +++++++++-- .../federation/organizations/IndexPage.java | 33 +++++++++++-------- 3 files changed, 38 insertions(+), 17 deletions(-) diff --git a/src/fr/devinsy/statoolinfosweb/CrawlCacheChecker.java b/src/fr/devinsy/statoolinfosweb/CrawlCacheChecker.java index 6c5d756..b7e77e8 100644 --- a/src/fr/devinsy/statoolinfosweb/CrawlCacheChecker.java +++ b/src/fr/devinsy/statoolinfosweb/CrawlCacheChecker.java @@ -106,7 +106,7 @@ public class CrawlCacheChecker implements ServletContextListener @Override public void contextDestroyed(ServletContextEvent event) { - logger.info("Stopping checker thread."); + logger.info("Stopping checker thread…"); this.checker.interrupt(); } } diff --git a/src/fr/devinsy/statoolinfosweb/StatoolInfosWeb.java b/src/fr/devinsy/statoolinfosweb/StatoolInfosWeb.java index d523a04..c0b2c68 100644 --- a/src/fr/devinsy/statoolinfosweb/StatoolInfosWeb.java +++ b/src/fr/devinsy/statoolinfosweb/StatoolInfosWeb.java @@ -28,6 +28,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.exception.ExceptionUtils; import fr.devinsy.kiss4web.EnvironmentInformation; +import fr.devinsy.kiss4web.HtmlCache; import fr.devinsy.kiss4web.Kiss4web; import fr.devinsy.kiss4web.Kiss4web.Mode; import fr.devinsy.kiss4web.dispatcher.KissDispatcher; @@ -69,6 +70,7 @@ public class StatoolInfosWeb private File configurationFile; private BuildInformation buildInformation; private StatoolInfosContext context; + private HtmlCache htmlCache; /** * Instantiates a new manager. @@ -81,6 +83,9 @@ public class StatoolInfosWeb // try { + // + this.htmlCache = new HtmlCache(); + // currentLog = "StatoolInfosWeb"; logger.info("StatoolInfosWeb initializing..."); @@ -189,14 +194,14 @@ public class StatoolInfosWeb { if (this.context.isExpired()) { - logger.info("Context expired, reloading context…"); + logger.info("Context expiration: KO, reloading context…"); StatoolInfosContext newContext = new StatoolInfosContext(this.configurationFile); this.context = newContext; clear(); } else { - logger.info("Context expiration not detected."); + logger.info("Context expiration: OK."); } } catch (StatoolInfosException | IOException exception) @@ -212,6 +217,17 @@ public class StatoolInfosWeb public void clear() { KissDispatcher.instance().clear(); + this.htmlCache.clear(); + } + + /** + * Gets the html cache. + * + * @return the html cache + */ + public HtmlCache getHtmlCache() + { + return this.htmlCache; } /** diff --git a/src/website/federation/organizations/IndexPage.java b/src/website/federation/organizations/IndexPage.java index 7ecc491..5ea7b73 100644 --- a/src/website/federation/organizations/IndexPage.java +++ b/src/website/federation/organizations/IndexPage.java @@ -52,24 +52,29 @@ public class IndexPage extends HttpServlet { try { - // Get parameters. - // =============== + String html = StatoolInfosWeb.instance().getHtmlCache().get(IndexPage.class.getCanonicalName()); + if (html == null) + { + // Get parameters. + // =============== - // Use parameters. - // =============== - Federation federation = StatoolInfosWeb.instance().getFederation(); - UptimeJournal uptimes = StatoolInfosWeb.instance().getUptimeJournal(); + // Use parameters. + // =============== + Federation federation = StatoolInfosWeb.instance().getFederation(); + UptimeJournal uptimes = StatoolInfosWeb.instance().getUptimeJournal(); - // Send response. - // ============== - String headerView = FederationHeaderView.htmlize(federation, uptimes); - String contentView = OrganizationListView.htmlize(federation.getMemberOrganizations(), federation.getAwayOrganizations()); + // Send response. + // ============== + String headerView = FederationHeaderView.htmlize(federation, uptimes); + String contentView = OrganizationListView.htmlize(federation.getMemberOrganizations(), federation.getAwayOrganizations()); - BreadcrumbTrail trail = new BreadcrumbTrail(); - trail.add(federation.getName(), "/federation/organizations/"); - trail.add("Organisations", "/federation/organizations/"); + BreadcrumbTrail trail = new BreadcrumbTrail(); + trail.add(federation.getName(), "/federation/organizations/"); + trail.add("Organisations", "/federation/organizations/"); - String html = WebCharterView.build(headerView, contentView, trail); + html = WebCharterView.build(headerView, contentView, trail); + StatoolInfosWeb.instance().getHtmlCache().put(IndexPage.class.getCanonicalName(), html); + } // Display page. response.setContentType("application/xhtml+xml; charset=UTF-8");