BlockCache class
BlockCache is used to cache the compilation of templates into Blocks. It can be used synchronously if HTML is known or asynchronously if the template HTML needs to be looked up from the URL.
class BlockCache { // _blockFactoryCache is unbounded Cache<String, BlockFactory> _blockFactoryCache = new LruCache<String, BlockFactory>(capacity: 0); Http $http; TemplateCache $templateCache; Compiler compiler; dom.NodeTreeSanitizer treeSanitizer; BlockCache(Http this.$http, TemplateCache this.$templateCache, Compiler this.compiler, dom.NodeTreeSanitizer this.treeSanitizer); BlockFactory fromHtml(String html) { BlockFactory blockFactory = _blockFactoryCache.get(html); if (blockFactory == null) { var div = new dom.Element.tag('div'); div.setInnerHtml(html, treeSanitizer: treeSanitizer); blockFactory = compiler(div.nodes); _blockFactoryCache.put(html, blockFactory); } return blockFactory; } async.Future<BlockFactory> fromUrl(String url) { return $http.getString(url, cache: $templateCache).then(fromHtml); } }
Constructors
new BlockCache(Http $http, TemplateCache $templateCache, Compiler compiler, NodeTreeSanitizer treeSanitizer) #
Creates a new Object instance.
Object instances have no meaningful state, and are only useful through their identity. An Object instance is equal to itself only.
docs inherited from Object
BlockCache(Http this.$http, TemplateCache this.$templateCache, Compiler this.compiler, dom.NodeTreeSanitizer this.treeSanitizer);
Properties
TemplateCache $templateCache #
TemplateCache $templateCache
NodeTreeSanitizer treeSanitizer #
dom.NodeTreeSanitizer treeSanitizer
Methods
BlockFactory fromHtml(String html) #
BlockFactory fromHtml(String html) { BlockFactory blockFactory = _blockFactoryCache.get(html); if (blockFactory == null) { var div = new dom.Element.tag('div'); div.setInnerHtml(html, treeSanitizer: treeSanitizer); blockFactory = compiler(div.nodes); _blockFactoryCache.put(html, blockFactory); } return blockFactory; }
Future<BlockFactory> fromUrl(String url) #
async.Future<BlockFactory> fromUrl(String url) { return $http.getString(url, cache: $templateCache).then(fromHtml); }