浏览代码

getTemplateByString 避免创建 StringSource

James 4 年之前
父节点
当前提交
673d4176b8
共有 1 个文件被更改,包括 3 次插入4 次删除
  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));
 			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);
 		Template template = templateCache.get(cacheKey);
 		if (template == null) {
 		if (template == null) {
-			template = buildTemplateBySource(source);
+			template = buildTemplateBySource(new StringSource(content, cacheKey));
 			templateCache.put(cacheKey, template);
 			templateCache.put(cacheKey, template);
 		} else if (devMode) {
 		} else if (devMode) {
 			if (template.isModified()) {
 			if (template.isModified()) {
-				template = buildTemplateBySource(source);
+				template = buildTemplateBySource(new StringSource(content, cacheKey));
 				templateCache.put(cacheKey, template);
 				templateCache.put(cacheKey, template);
 			}
 			}
 		}
 		}