Browse Source

getTemplateByString 避免创建 StringSource

James 4 years ago
parent
commit
673d4176b8
1 changed files with 3 additions and 4 deletions
  1. 3 4
      src/main/java/com/jfinal/template/Engine.java

+ 3 - 4
src/main/java/com/jfinal/template/Engine.java

@@ -197,15 +197,14 @@ public class Engine {
 			return buildTemplateBySource(new StringSource(content, cache));
 		}
 		
-		StringSource source = new StringSource(content, cache);
-		String cacheKey = source.getCacheKey();
+		String cacheKey = HashKit.md5(content);
 		Template template = templateCache.get(cacheKey);
 		if (template == null) {
-			template = buildTemplateBySource(source);
+			template = buildTemplateBySource(new StringSource(content, cacheKey));
 			templateCache.put(cacheKey, template);
 		} else if (devMode) {
 			if (template.isModified()) {
-				template = buildTemplateBySource(source);
+				template = buildTemplateBySource(new StringSource(content, cacheKey));
 				templateCache.put(cacheKey, template);
 			}
 		}