*) httpdFileHandler templateCache can now be disabled

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@708 6c8d7289-2bf4-0310-a012-ef5d649a1542
This commit is contained in:
theli 2005-09-12 10:47:27 +00:00
parent 2cb084d426
commit a6a8af0f04
2 changed files with 38 additions and 24 deletions

View File

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

View File

@ -518,3 +518,5 @@ crawler.MaxIdleThreads = 7
crawler.MinIdleThreads = 5
useYacyReferer = true
enableTemplateCache = true