Skip to content

Commit 5900370

Browse files
jbdeboertravis@travis-ci.org
authored andcommitted
feat(cache): Add existing caches to CacheRegister
Closes dart-archive#1165
1 parent be62c48 commit 5900370

8 files changed

+28
-5
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 = new HashMap();
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
@@ -14,6 +14,7 @@ import 'package:angular/utils.dart';
1414

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

17+
import 'package:angular/cache/module.dart';
1718
import 'package:angular/change_detection/watch_group.dart';
1819
export 'package:angular/change_detection/watch_group.dart';
1920
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 = new HashMap<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
@@ -58,7 +58,11 @@ class CoreDomModule extends Module {
5858
bind(ElementProbe, toValue: null);
5959

6060
// Default to a unlimited-sized TemplateCache
61-
bind(TemplateCache, toFactory: (_) => new TemplateCache());
61+
bind(TemplateCache, toFactory: (i) {
62+
var templateCache = new TemplateCache();
63+
i.getByKey(CACHE_REGISTER_KEY).registerCache("TemplateCache", templateCache);
64+
return templateCache;
65+
});
6266
bind(dom.NodeTreeSanitizer, toImplementation: NullTreeSanitizer);
6367

6468
bind(TextMustache);

lib/core_dom/shadow_dom_component_factory.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ class ShadowDomComponentFactory implements ComponentFactory {
4545

4646
final Map<_ComponentAssetKey, async.Future<dom.StyleElement>> styleElementCache = {};
4747

48-
ShadowDomComponentFactory(this.viewCache, this.http, this.templateCache, this.platform, this.componentCssRewriter, this.treeSanitizer, this.expando, this.config);
48+
ShadowDomComponentFactory(this.viewCache, this.http, this.templateCache, this.platform,
49+
this.componentCssRewriter, this.treeSanitizer, this.expando,
50+
this.config, CacheRegister cacheRegister) {
51+
cacheRegister.registerCache("ShadowDomComponentFactoryStyles", styleElementCache);
52+
}
4953

5054
bind(DirectiveRef ref, directives) =>
5155
new BoundShadowDomComponentFactory(this, ref, directives);

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)