Added a html cache feature.

This commit is contained in:
Christian P. MOMON 2024-08-12 17:32:50 +02:00
parent ac1527f2c4
commit df19b3b732
3 changed files with 38 additions and 17 deletions

View file

@ -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();
}
}

View file

@ -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;
}
/**

View file

@ -51,6 +51,9 @@ public class IndexPage extends HttpServlet
public void doGet(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException
{
try
{
String html = StatoolInfosWeb.instance().getHtmlCache().get(IndexPage.class.getCanonicalName());
if (html == null)
{
// Get parameters.
// ===============
@ -69,7 +72,9 @@ public class IndexPage extends HttpServlet
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");