Browse Source

update src/main/java/com/jfinal/template/Engine.java.

hzh740053757 4 years ago
parent
commit
f0f01a3e6c
1 changed files with 18 additions and 0 deletions
  1. 18 0
      src/main/java/com/jfinal/template/Engine.java

+ 18 - 0
src/main/java/com/jfinal/template/Engine.java

@@ -210,6 +210,24 @@ public class Engine {
 		}
 		return template;
 	}
+
+    public Template getTemplateByString(String content, String cacheKey) {
+		if (cacheKey == null) {
+			return buildTemplateBySource(new StringSource(content, cacheKey));
+		}
+        
+		Template template = templateCache.get(cacheKey);
+		if (template == null) {
+			template = buildTemplateBySource(new StringSource(content, cacheKey));
+			templateCache.put(cacheKey, template);
+		} else if (devMode) {
+			if (template.isModified()) {
+				template = buildTemplateBySource(new StringSource(content, cacheKey));
+				templateCache.put(cacheKey, template);
+			}
+		}
+		return template;
+	}
 	
 	/**
 	 * Get template by implementation of ISource