Browse Source

jfinal 3.5

James 7 years ago
parent
commit
464bbd4b6b

+ 20 - 20
src/main/java/com/jfinal/template/Engine.java

@@ -126,7 +126,7 @@ public class Engine {
 	}
 	}
 	
 	
 	/**
 	/**
-	 * Get template with file name
+	 * Get template by file name
 	 */
 	 */
 	public Template getTemplate(String fileName) {
 	public Template getTemplate(String fileName) {
 		if (fileName.charAt(0) != '/') {
 		if (fileName.charAt(0) != '/') {
@@ -172,9 +172,9 @@ public class Engine {
 	/**
 	/**
 	 * Get template by string content
 	 * Get template by string content
 	 * 
 	 * 
-	 * 重要:StringSource 中的 key = HashKit.md5(content),也即 key
-	 *     与 content 有紧密的对应关系,当 content 发生变化时 key 值也相应变化
-	 *     因此,原先 key 所对应的 Template 缓存对象已无法被获取,当 getTemplateByString(String)
+	 * 重要:StringSource 中的 cacheKey = HashKit.md5(content),也即 cacheKey
+	 *     与 content 有紧密的对应关系,当 content 发生变化时 cacheKey 值也相应变化
+	 *     因此,原先 cacheKey 所对应的 Template 缓存对象已无法被获取,当 getTemplateByString(String)
 	 *     的 String 参数的数量不确定时会引发内存泄漏
 	 *     的 String 参数的数量不确定时会引发内存泄漏
 	 *     
 	 *     
 	 *     当 getTemplateByString(String, boolean) 中的 String 参数的
 	 *     当 getTemplateByString(String, boolean) 中的 String 参数的
@@ -188,37 +188,37 @@ public class Engine {
 			return buildTemplateBySource(new StringSource(content, cache));
 			return buildTemplateBySource(new StringSource(content, cache));
 		}
 		}
 		
 		
-		String key = HashKit.md5(content);
-		Template template = templateCache.get(key);
+		String cacheKey = HashKit.md5(content);
+		Template template = templateCache.get(cacheKey);
 		if (template == null) {
 		if (template == null) {
 			template = buildTemplateBySource(new StringSource(content, cache));
 			template = buildTemplateBySource(new StringSource(content, cache));
-			templateCache.put(key, template);
+			templateCache.put(cacheKey, template);
 		} else if (devMode) {
 		} else if (devMode) {
 			if (template.isModified()) {
 			if (template.isModified()) {
 				template = buildTemplateBySource(new StringSource(content, cache));
 				template = buildTemplateBySource(new StringSource(content, cache));
-				templateCache.put(key, template);
+				templateCache.put(cacheKey, template);
 			}
 			}
 		}
 		}
 		return template;
 		return template;
 	}
 	}
 	
 	
 	/**
 	/**
-	 * Get template with implementation of ISource
+	 * Get template by implementation of ISource
 	 */
 	 */
 	public Template getTemplate(ISource source) {
 	public Template getTemplate(ISource source) {
-		String key = source.getKey();
-		if (key == null) {	// key 为 null 则不缓存,详见 ISource.getKey() 注释
+		String cacheKey = source.getCacheKey();
+		if (cacheKey == null) {	// cacheKey 为 null 则不缓存,详见 ISource.getCacheKey() 注释
 			return buildTemplateBySource(source);
 			return buildTemplateBySource(source);
 		}
 		}
 		
 		
-		Template template = templateCache.get(key);
+		Template template = templateCache.get(cacheKey);
 		if (template == null) {
 		if (template == null) {
 			template = buildTemplateBySource(source);
 			template = buildTemplateBySource(source);
-			templateCache.put(key, template);
+			templateCache.put(cacheKey, template);
 		} else if (devMode) {
 		} else if (devMode) {
 			if (template.isModified()) {
 			if (template.isModified()) {
 				template = buildTemplateBySource(source);
 				template = buildTemplateBySource(source);
-				templateCache.put(key, template);
+				templateCache.put(cacheKey, template);
 			}
 			}
 		}
 		}
 		return template;
 		return template;
@@ -236,7 +236,7 @@ public class Engine {
 	}
 	}
 	
 	
 	/**
 	/**
-	 * Add shared function with file
+	 * Add shared function by file
 	 */
 	 */
 	public Engine addSharedFunction(String fileName) {
 	public Engine addSharedFunction(String fileName) {
 		config.addSharedFunction(fileName);
 		config.addSharedFunction(fileName);
@@ -252,7 +252,7 @@ public class Engine {
 	}
 	}
 	
 	
 	/**
 	/**
-	 * Add shared function with files
+	 * Add shared function by files
 	 */
 	 */
 	public Engine addSharedFunction(String... fileNames) {
 	public Engine addSharedFunction(String... fileNames) {
 		config.addSharedFunction(fileNames);
 		config.addSharedFunction(fileNames);
@@ -336,7 +336,7 @@ public class Engine {
 	}
 	}
 	
 	
 	/**
 	/**
-	 * Remove shared Method with method name
+	 * Remove shared Method by method name
 	 */
 	 */
 	public Engine removeSharedMethod(String methodName) {
 	public Engine removeSharedMethod(String methodName) {
 		config.removeSharedMethod(methodName);
 		config.removeSharedMethod(methodName);
@@ -360,10 +360,10 @@ public class Engine {
 	}
 	}
 	
 	
 	/**
 	/**
-	 * Remove template cache with template key
+	 * Remove template cache by cache key
 	 */
 	 */
-	public void removeTemplateCache(String templateKey) {
-		templateCache.remove(templateKey);
+	public void removeTemplateCache(String cacheKey) {
+		templateCache.remove(cacheKey);
 	}
 	}
 	
 	
 	/**
 	/**

+ 1 - 1
src/main/java/com/jfinal/template/source/ClassPathSource.java

@@ -105,7 +105,7 @@ public class ClassPathSource implements ISource {
 		return finalFileName;
 		return finalFileName;
 	}
 	}
 	
 	
-	public String getKey() {
+	public String getCacheKey() {
 		return fileName;
 		return fileName;
 	}
 	}
 	
 	

+ 1 - 1
src/main/java/com/jfinal/template/source/FileSource.java

@@ -48,7 +48,7 @@ public class FileSource implements ISource {
 		return lastModified != new File(finalFileName).lastModified();
 		return lastModified != new File(finalFileName).lastModified();
 	}
 	}
 	
 	
-	public String getKey() {
+	public String getCacheKey() {
 		return fileName;
 		return fileName;
 	}
 	}
 	
 	

+ 3 - 3
src/main/java/com/jfinal/template/source/ISource.java

@@ -27,12 +27,12 @@ public interface ISource {
 	boolean isModified();
 	boolean isModified();
 	
 	
 	/**
 	/**
-	 * key used to cache, return null if do not cache the template
+	 * cache key used to cache, return null if do not cache the template
 	 * 
 	 * 
 	 * 注意:如果不希望缓存从该 ISource 解析出来的 Template 对象
 	 * 注意:如果不希望缓存从该 ISource 解析出来的 Template 对象
-	 *      让 getKey() 返回 null 值即可  
+	 *      让 getCacheKey() 返回 null 值即可  
 	 */
 	 */
-	String getKey();
+	String getCacheKey();
 	
 	
 	/**
 	/**
 	 * content of ISource
 	 * content of ISource

+ 7 - 7
src/main/java/com/jfinal/template/source/StringSource.java

@@ -25,7 +25,7 @@ import com.jfinal.template.EngineConfig;
  */
  */
 public class StringSource implements ISource {
 public class StringSource implements ISource {
 	
 	
-	private String key;
+	private String cacheKey;
 	private StringBuilder content;
 	private StringBuilder content;
 	
 	
 	/**
 	/**
@@ -38,7 +38,7 @@ public class StringSource implements ISource {
 			throw new IllegalArgumentException("content can not be blank");
 			throw new IllegalArgumentException("content can not be blank");
 		}
 		}
 		this.content = new StringBuilder(content);
 		this.content = new StringBuilder(content);
-		this.key = cache ? HashKit.md5(content) : null;	// 不缓存只要将 key 值赋为 null 即可
+		this.cacheKey = cache ? HashKit.md5(content) : null;	// 不缓存只要将 cacheKey 值赋为 null 即可
 	}
 	}
 	
 	
 	public StringSource(StringBuilder content, boolean cache) {
 	public StringSource(StringBuilder content, boolean cache) {
@@ -46,15 +46,15 @@ public class StringSource implements ISource {
 			throw new IllegalArgumentException("content can not be blank");
 			throw new IllegalArgumentException("content can not be blank");
 		}
 		}
 		this.content = content;
 		this.content = content;
-		this.key = cache ? HashKit.md5(content.toString()) : null;	// 不缓存只要将 key 值赋为 null 即可
+		this.cacheKey = cache ? HashKit.md5(content.toString()) : null;	// 不缓存只要将 cacheKey 值赋为 null 即可
 	}
 	}
 	
 	
 	public boolean isModified() {
 	public boolean isModified() {
 		return false;
 		return false;
 	}
 	}
 	
 	
-	public String getKey() {
-		return key;
+	public String getCacheKey() {
+		return cacheKey;
 	}
 	}
 	
 	
 	public StringBuilder getContent() {
 	public StringBuilder getContent() {
@@ -67,8 +67,8 @@ public class StringSource implements ISource {
 	
 	
 	public String toString() {
 	public String toString() {
 		StringBuilder sb = new StringBuilder();
 		StringBuilder sb = new StringBuilder();
-		sb.append("Key : ").append(key).append("\n");
-		sb.append("Content : ").append(content).append("\n");
+		sb.append("cacheKey : ").append(cacheKey).append("\n");
+		sb.append("content : ").append(content).append("\n");
 		return sb.toString();
 		return sb.toString();
 	}
 	}
 }
 }