diff --git a/source/de/anomic/http/httpdFileHandler.java b/source/de/anomic/http/httpdFileHandler.java index 3a4adb50b..8497f9599 100644 --- a/source/de/anomic/http/httpdFileHandler.java +++ b/source/de/anomic/http/httpdFileHandler.java @@ -108,8 +108,12 @@ public final class httpdFileHandler { private static String[] defaultFiles = null; private static File htDefaultPath = null; private static File htLocalePath = null; - - private static final HashMap> templateCache; + + private static final class TemplateCacheEntry { + Date lastModified; + byte[] content; + } + private static final HashMap> templateCache; private static final HashMap> templateMethodCache; public static final boolean useTemplateCache; @@ -121,7 +125,7 @@ public final class httpdFileHandler { static { final serverSwitch theSwitchboard = plasmaSwitchboard.getSwitchboard(); useTemplateCache = theSwitchboard.getConfig("enableTemplateCache","true").equalsIgnoreCase("true"); - templateCache = (useTemplateCache)? new HashMap>() : new HashMap>(0); + templateCache = (useTemplateCache)? new HashMap>() : new HashMap>(0); templateMethodCache = (useTemplateCache) ? new HashMap>() : new HashMap>(0); if (httpdFileHandler.switchboard == null) { @@ -661,24 +665,27 @@ public final class httpdFileHandler { InputStream fis = null; // read the file/template - byte[] templateContent = null; + TemplateCacheEntry templateCacheEntry = null; if (useTemplateCache) { final long fileSize = targetFile.length(); if (fileSize <= 512 * 1024) { // read from cache - SoftReference ref = templateCache.get(targetFile); + SoftReference ref = templateCache.get(targetFile); if (ref != null) { - templateContent = ref.get(); - if (templateContent == null) templateCache.remove(targetFile); + templateCacheEntry = ref.get(); + if (templateCacheEntry == null) templateCache.remove(targetFile); } - if (templateContent == null) { + Date targetFileDate = new Date(targetFile.lastModified()); + if (templateCacheEntry == null || targetFileDate.after(templateCacheEntry.lastModified)) { // loading the content of the template file into // a byte array - templateContent = serverFileUtils.read(targetFile); + templateCacheEntry = new TemplateCacheEntry(); + templateCacheEntry.lastModified = targetFileDate; + templateCacheEntry.content = serverFileUtils.read(targetFile); // storing the content into the cache - ref = new SoftReference(templateContent); + ref = new SoftReference(templateCacheEntry); templateCache.put(targetFile, ref); if (theLogger.isFinest()) theLogger.logFinest("Cache MISS for file " + targetFile); } else { @@ -687,8 +694,8 @@ public final class httpdFileHandler { // creating an inputstream needed by the template // rewrite function - fis = new ByteArrayInputStream(templateContent); - templateContent = null; + fis = new ByteArrayInputStream(templateCacheEntry.content); + templateCacheEntry = null; } else { // read from file directly fis = new BufferedInputStream(new FileInputStream(targetFile));