分析 Dojo 源代碼時遇到 Cache, 以及pendingCacheInsert不是很理解,在Dojo官方網站找到這篇文章。 http://dojotoolkit.org/reference-guide/1.7/dojo/cache.html.
Dojo Cache 是通過getter 和 setter方法 獲取和存儲模塊和指定URL相關的字符串。 這種存取方法已經被dojo/text!插件替代。寫這篇文檔主要作用是爲了給 1.4 版本的用戶。
介紹
使用
// Dojo 1.7 (AMD)
require("dojo/text", function(){
// write your code here
});
// Dojo < 1.7
dojo.require("dojo.cache");
dojo.cache 採用以下的參數 dojo.cache(module, url, configValue);
舉例
// Dojo 1.7 (AMD)
require("dojo/text", function(){
var text = dojo.cache("my.module", "template.html");
});
// Dojo 1.7
dojo.require("dojo.cache");
var text = dojo.cache("my.module", "template.html");
如果 "my/module/template.html" 包含 "<div>Hello World</div>", 則 text變量將被設置爲這個值。// Dojo 1.7 (AMD)
require("dojo/text", function(){
var text = dojo.cache("my.module", "template.html", {sanitize: true});
});
// Dojo < 1.7
dojo.require("dojo.cache");
var text = dojo.cache("my.module", "template.html");
如果 my/module/template.html 包含 "<html><body><h1>Hello</h1></body></html>", 則 text變量將只會包含"<h1>Hello</h1>".
// Dojo 1.7 (AMD)
require("dojo/text", function(){
var text = dojo.cache(new dojo._Url("my/module/template.html"), {sanitize: true});
});
dojo.require("dojo.cache");
var text = dojo.cache(new dojo._Url("my/module/template.html"), {sanitize: true});
獲得更詳細的信息,請查看