From d1dbbd956a4e607b1472f564c455d9f8960196e2 Mon Sep 17 00:00:00 2001 From: orbiter Date: Tue, 24 May 2011 09:31:07 +0000 Subject: [PATCH] always use a template method cache even if the template cache flag is set to false. This flag is only used to make dynamic updates to the template files, to not dynamic updates to the rewrite methods (which is not possible without recompiling). low memory usage is guaranteed by the usage of soft references which are dropped before an OOM is thrown git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7735 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- source/de/anomic/http/server/HTTPDFileHandler.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/source/de/anomic/http/server/HTTPDFileHandler.java b/source/de/anomic/http/server/HTTPDFileHandler.java index 36728339a..63dee4f34 100644 --- a/source/de/anomic/http/server/HTTPDFileHandler.java +++ b/source/de/anomic/http/server/HTTPDFileHandler.java @@ -145,7 +145,7 @@ public final class HTTPDFileHandler { final serverSwitch theSwitchboard = Switchboard.getSwitchboard(); useTemplateCache = theSwitchboard.getConfig("enableTemplateCache","true").equalsIgnoreCase("true"); templateCache = (useTemplateCache)? new ConcurrentHashMap>() : new ConcurrentHashMap>(0); - templateMethodCache = (useTemplateCache) ? new ConcurrentHashMap>() : new ConcurrentHashMap>(0); + templateMethodCache = new ConcurrentHashMap>(); if (switchboard == null) { switchboard = theSwitchboard; @@ -1217,7 +1217,7 @@ public final class HTTPDFileHandler { Method m = null; // now make a class out of the stream try { - if (useTemplateCache) { + if (templateMethodCache != null) { final SoftReference ref = templateMethodCache.get(classFile); if (ref != null) { m = ref.get(); @@ -1226,7 +1226,7 @@ public final class HTTPDFileHandler { } else { return m; } - } + } } final Class c = provider.loadClass(classFile); @@ -1236,10 +1236,11 @@ public final class HTTPDFileHandler { serverSwitch.class }; m = c.getMethod("respond", params); - if (useTemplateCache) { + if (MemoryControl.shortStatus()) { + templateMethodCache.clear(); + } else { // storing the method into the cache final SoftReference ref = new SoftReference(m); - if (MemoryControl.shortStatus()) templateMethodCache.clear(); templateMethodCache.put(classFile, ref); }