diff --git a/source/de/anomic/http/httpdFileHandler.java b/source/de/anomic/http/httpdFileHandler.java index 1d2827d72..de258e427 100644 --- a/source/de/anomic/http/httpdFileHandler.java +++ b/source/de/anomic/http/httpdFileHandler.java @@ -74,6 +74,7 @@ package de.anomic.http; +import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; @@ -97,6 +98,7 @@ import java.util.Properties; import java.util.logging.Level; import java.util.zip.GZIPOutputStream; +import de.anomic.plasma.plasmaSwitchboard; import de.anomic.server.serverClassLoader; import de.anomic.server.serverCodings; import de.anomic.server.serverCore; @@ -126,6 +128,12 @@ public final class httpdFileHandler extends httpdAbstractHandler implements http */ private static final HashMap templateCache = new HashMap(); + public static boolean useTemplateCache = false; + + static { + useTemplateCache = plasmaSwitchboard.getSwitchboard().getConfig("enableTemplateCache","true").equalsIgnoreCase("true"); + } + public httpdFileHandler(serverSwitch switchboard) { this.switchboard = switchboard; @@ -474,34 +482,38 @@ public final class httpdFileHandler extends httpdAbstractHandler implements http try { // do fileCaching here byte[] templateContent = null; - long fileSize = localizedFile.length(); - if (fileSize <= 512*1024) { - SoftReference ref = (SoftReference) templateCache.get(localizedFile); - if (ref != null) { - templateContent = (byte[]) ref.get(); - if (templateContent == null) - templateCache.remove(localizedFile); - } - - if (templateContent == null) { - // loading the content of the template file into a byte array - templateContent = serverFileUtils.read(localizedFile); + if (useTemplateCache) { + long fileSize = localizedFile.length(); + if (fileSize <= 512*1024) { + SoftReference ref = (SoftReference) templateCache.get(localizedFile); + if (ref != null) { + templateContent = (byte[]) ref.get(); + if (templateContent == null) + templateCache.remove(localizedFile); + } + + if (templateContent == null) { + // loading the content of the template file into a byte array + templateContent = serverFileUtils.read(localizedFile); + + // storing the content into the cache + ref = new SoftReference(templateContent); + templateCache.put(localizedFile,ref); + if (this.theLogger.isLoggable(Level.FINEST)) + this.theLogger.logFinest("Cache MISS for file " + localizedFile); + } else { + if (this.theLogger.isLoggable(Level.FINEST)) + this.theLogger.logFinest("Cache HIT for file " + localizedFile); + } - // storing the content into the cache - ref = new SoftReference(templateContent); - templateCache.put(localizedFile,ref); - if (this.theLogger.isLoggable(Level.FINEST)) - this.theLogger.logFinest("Cache MISS for file " + localizedFile); + // creating an inputstream needed by the template rewrite function + fis = new ByteArrayInputStream(templateContent); + templateContent = null; } else { - if (this.theLogger.isLoggable(Level.FINEST)) - this.theLogger.logFinest("Cache HIT for file " + localizedFile); + fis = new BufferedInputStream(new FileInputStream(localizedFile)); } - - // creating an inputstream needed by the template rewrite function - fis = new ByteArrayInputStream(templateContent); - templateContent = null; } else { - fis = new FileInputStream(localizedFile); + fis = new BufferedInputStream(new FileInputStream(localizedFile)); } o = new ByteArrayOutputStream(); diff --git a/yacy.init b/yacy.init index be2fb9ee8..a608251eb 100644 --- a/yacy.init +++ b/yacy.init @@ -518,3 +518,5 @@ crawler.MaxIdleThreads = 7 crawler.MinIdleThreads = 5 useYacyReferer = true + +enableTemplateCache = true \ No newline at end of file