Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 1b84199

Browse files
committed
feat(cache): Add existing caches to CacheRegister
Closes #1165
1 parent 065e34d commit 1b84199

8 files changed

+26
-6
lines changed

lib/core/interpolate.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ part of angular.core_internal;
1111
@Injectable()
1212
class Interpolate implements Function {
1313
var _cache = {};
14+
15+
Interpolate(CacheRegister cacheRegister) {
16+
cacheRegister.registerCache("Interpolate", _cache);
17+
}
1418
/**
1519
* Compiles markup text into expression.
1620
*

lib/core/module_internal.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import 'package:angular/utils.dart';
1313

1414
import 'package:angular/core/annotation_src.dart';
1515

16+
import 'package:angular/cache/module.dart';
1617
import 'package:angular/change_detection/watch_group.dart';
1718
export 'package:angular/change_detection/watch_group.dart';
1819
import 'package:angular/change_detection/ast_parser.dart';

lib/core/parser/dynamic_parser.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
library angular.core.parser.dynamic_parser;
22

3+
import 'package:angular/cache/module.dart';
34
import 'package:angular/core/annotation_src.dart' hide Formatter;
45
import 'package:angular/core/module_internal.dart' show FormatterMap;
56

@@ -24,7 +25,9 @@ class DynamicParser implements Parser<Expression> {
2425
final Lexer _lexer;
2526
final ParserBackend _backend;
2627
final Map<String, Expression> _cache = {};
27-
DynamicParser(this._lexer, this._backend);
28+
DynamicParser(this._lexer, this._backend, CacheRegister cacheRegister) {
29+
cacheRegister.registerCache("DynamicParser", _cache);
30+
}
2831

2932
Expression call(String input) {
3033
if (input == null) input = '';

lib/core/parser/static_parser.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
library angular.core.parser.static_parser;
22

3+
import 'package:angular/cache/module.dart' show CacheRegister;
34
import 'package:angular/core/annotation_src.dart' show Injectable;
45
import 'package:angular/core/module_internal.dart' show FormatterMap;
56
import 'package:angular/core/parser/parser.dart';
@@ -17,7 +18,9 @@ class StaticParser implements Parser<Expression> {
1718
final StaticParserFunctions _functions;
1819
final DynamicParser _fallbackParser;
1920
final _cache = <String, Expression>{};
20-
StaticParser(this._functions, this._fallbackParser);
21+
StaticParser(this._functions, this._fallbackParser, CacheRegister cacheRegister) {
22+
cacheRegister.registerCache("StaticParser", _cache);
23+
}
2124

2225
Expression call(String input) {
2326
if (input == null) input = '';

lib/core_dom/module_internal.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ class CoreDomModule extends Module {
5454
bind(ElementProbe, toValue: null);
5555

5656
// Default to a unlimited-sized TemplateCache
57-
bind(TemplateCache, toFactory: (_) => new TemplateCache());
57+
bind(TemplateCache, toFactory: (i) {
58+
var templateCache = new TemplateCache();
59+
i.getByKey(CACHE_REGISTER_KEY).registerCache("TemplateCache", templateCache);
60+
return templateCache;
61+
});
5862
bind(dom.NodeTreeSanitizer, toImplementation: NullTreeSanitizer);
5963

6064
bind(TextMustache);

lib/core_dom/shadow_dom_component_factory.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ class ShadowDomComponentFactory implements ComponentFactory {
3030
final Expando _expando;
3131
final CompilerConfig _config;
3232

33-
ShadowDomComponentFactory(this._expando, this._config);
33+
ShadowDomComponentFactory(this._expando, this._config, CacheRegister cacheRegister) {
34+
cacheRegister.registerCache("ShadowDomComponentFactoryStyles", _styleElementCache);
35+
}
3436

3537
final Map<String, async.Future<dom.StyleElement>> _styleElementCache = {};
36-
3738

3839

3940
FactoryFn call(dom.Node node, DirectiveRef ref) {

lib/core_dom/static_keys.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ library angular.core_dom.static_keys;
22

33
import 'dart:html' as dom;
44
import 'package:di/di.dart';
5+
import 'package:angular/cache/module.dart';
56
import 'package:angular/core/static_keys.dart';
67
import 'package:angular/core_dom/module_internal.dart';
78

@@ -12,6 +13,7 @@ export 'package:angular/core/static_keys.dart';
1213

1314
Key ANIMATE_KEY = new Key(Animate);
1415
Key BOUND_VIEW_FACTORY_KEY = new Key(BoundViewFactory);
16+
Key CACHE_REGISTER_KEY = new Key(CacheRegister);
1517
Key COMPILER_KEY = new Key(Compiler);
1618
Key COMPONENT_CSS_REWRITER_KEY = new Key(ComponentCssRewriter);
1719
Key DIRECTIVE_MAP_KEY = new Key(DirectiveMap);

lib/core_dom/view_factory.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ class ViewCache {
125125
final Compiler compiler;
126126
final dom.NodeTreeSanitizer treeSanitizer;
127127

128-
ViewCache(this.http, this.templateCache, this.compiler, this.treeSanitizer);
128+
ViewCache(this.http, this.templateCache, this.compiler, this.treeSanitizer, CacheRegister cacheRegister) {
129+
cacheRegister.registerCache('viewCache', _viewFactoryCache);
130+
}
129131

130132
ViewFactory fromHtml(String html, DirectiveMap directives) {
131133
ViewFactory viewFactory = _viewFactoryCache.get(html);

0 commit comments

Comments
 (0)