This repository was archived by the owner on Feb 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 248
feat(cache): Move cache out of core, add a CacheRegister #1165
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
part of angular.cache; | ||
|
||
class CacheRegisterStats { | ||
final String name; | ||
int length; | ||
|
||
CacheRegisterStats(this.name); | ||
} | ||
|
||
@Injectable() | ||
class CacheRegister { | ||
Map<String, dynamic> _caches = {}; | ||
List<CacheRegisterStats> _stats = null; | ||
|
||
/** | ||
* Registers a cache with the CacheRegister. The [name] is used for in the stats as | ||
* well as a key for [clear]. | ||
*/ | ||
void registerCache(String name, cache) { | ||
if (_caches.containsKey(name)) { | ||
throw "Cache [$name] already registered"; | ||
} | ||
_caches[name] = cache; | ||
|
||
// The stats object needs to be updated. | ||
_stats = null; | ||
|
||
} | ||
|
||
/** | ||
* A list of caches and their sizes. | ||
*/ | ||
List<CacheRegisterStats> get stats { | ||
if (_stats == null) { | ||
_stats = []; | ||
_caches.forEach((k, v) { | ||
_stats.add(new CacheRegisterStats(k)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}); | ||
} | ||
|
||
_stats.forEach((CacheRegisterStats stat) { | ||
stat.length = _caches[stat.name].length; | ||
}); | ||
return _stats; | ||
} | ||
|
||
/** | ||
* Clears one or all the caches. If [name] is omitted, all caches will be cleared. | ||
* Otherwise, only the cache named [name] will be cleared. | ||
*/ | ||
void clear([String name]) { | ||
if (name == null) { | ||
_caches.forEach((k, Map v) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
v.clear(); | ||
}); | ||
return; | ||
} | ||
var cache = _caches[name]; | ||
if (cache == null) { | ||
return; | ||
} | ||
_caches[name].clear(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
library angular.cache; | ||
|
||
import 'dart:collection'; | ||
import 'dart:async'; | ||
|
||
import 'package:di/di.dart'; | ||
import 'package:angular/core/annotation_src.dart'; | ||
|
||
part "cache.dart"; | ||
part "cache_register.dart"; | ||
|
||
class CacheModule extends Module { | ||
CacheModule() { | ||
bind(CacheRegister); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
library angular.core.parser.dynamic_parser; | ||
|
||
import 'package:angular/cache/module.dart'; | ||
import 'package:angular/core/annotation_src.dart' hide Formatter; | ||
import 'package:angular/core/module_internal.dart' show FormatterMap; | ||
|
||
|
@@ -24,7 +25,9 @@ class DynamicParser implements Parser<Expression> { | |
final Lexer _lexer; | ||
final ParserBackend _backend; | ||
final Map<String, Expression> _cache = {}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not directly related to this PR but could this be an |
||
DynamicParser(this._lexer, this._backend); | ||
DynamicParser(this._lexer, this._backend, CacheRegister cacheRegister) { | ||
cacheRegister.registerCache("DynamicParser", _cache); | ||
} | ||
|
||
Expression call(String input) { | ||
if (input == null) input = ''; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
library cache_register_spec; | ||
|
||
import '../_specs.dart'; | ||
|
||
main() => describe('CacheRegister', () { | ||
it('should clear caches', (CacheRegister register) { | ||
var map = {'a': 2}; | ||
var map2 = {'b': 3}; | ||
expect(map.length).toEqual(1); | ||
expect(map2.length).toEqual(1); | ||
|
||
register.registerCache('a', map); | ||
register.registerCache('b', map2); | ||
register.clear('a'); | ||
expect(map.length).toEqual(0); | ||
expect(map2.length).toEqual(1); | ||
|
||
map['a'] = 2; | ||
register.clear(); | ||
expect(map.length).toEqual(0); | ||
expect(map2.length).toEqual(0); | ||
|
||
|
||
}); | ||
|
||
it('should return stats when empty', (CacheRegister register) { | ||
expect(register.stats).toEqual([]); | ||
}); | ||
|
||
it('should return correct stats', (CacheRegister register) { | ||
var map = {'a': 2}; | ||
var map2 = {'b': 3, 'c': 4}; | ||
register.registerCache('a', map); | ||
register.registerCache('b', map2); | ||
|
||
expect(register.stats.length).toEqual(2); | ||
if (register.stats[0].name == 'a') { | ||
expect(register.stats[0].length).toEqual(1); | ||
expect(register.stats[1].name).toEqual('b'); | ||
expect(register.stats[1].length).toEqual(2); | ||
} else { | ||
expect(register.stats[0].name).toEqual('b'); | ||
expect(register.stats[0].length).toEqual(2); | ||
expect(register.stats[1].name).toEqual('a'); | ||
expect(register.stats[1].length).toEqual(1); | ||
} | ||
|
||
}); | ||
}); |
File renamed without changes.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Map
->Cache
on l. 19 - GH don't let me comment there :(There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently it should be
Map
(judging by Interpolate code) - what is the purpose ofCache
then ?