| OLD | NEW |
| 1 part of angular.core; | 1 part of angular.core_internal; |
| 2 | 2 |
| 3 class CacheStats { | 3 class CacheStats { |
| 4 final int capacity; | 4 final int capacity; |
| 5 final int size; | 5 final int size; |
| 6 final int hits; | 6 final int hits; |
| 7 final int misses; | 7 final int misses; |
| 8 CacheStats(this.capacity, this.size, this.hits, this.misses); | 8 CacheStats(this.capacity, this.size, this.hits, this.misses); |
| 9 String toString() => | 9 String toString() => |
| 10 "[CacheStats: capacity: $capacity, size: $size, hits: $hits, misses: $miss
es]"; | 10 "[CacheStats: capacity: $capacity, size: $size, hits: $hits, misses: $miss
es]"; |
| 11 } | 11 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 | 69 |
| 70 /** | 70 /** |
| 71 * Simple LRU cache. | 71 * Simple LRU cache. |
| 72 * | 72 * |
| 73 * TODO(chirayu): | 73 * TODO(chirayu): |
| 74 * - add docs | 74 * - add docs |
| 75 * - add tests | 75 * - add tests |
| 76 * - should stringify keys? | 76 * - should stringify keys? |
| 77 */ | 77 */ |
| 78 class LruCache<K, V> extends Cache<K, V> { | 78 class LruCache<K, V> extends Cache<K, V> { |
| 79 Map<K, V> _entries = new LinkedHashMap<K, V>(); | 79 final _entries = new LinkedHashMap<K, V>(); |
| 80 int _capacity; | 80 int _capacity; |
| 81 int _hits = 0; | 81 int _hits = 0; |
| 82 int _misses = 0; | 82 int _misses = 0; |
| 83 | 83 |
| 84 LruCache({int capacity}) { | 84 LruCache({int capacity}) { |
| 85 this._capacity = (capacity == null) ? 0 : capacity; | 85 this._capacity = (capacity == null) ? 0 : capacity; |
| 86 } | 86 } |
| 87 | 87 |
| 88 V get(K key) { | 88 V get(K key) { |
| 89 V value = _entries[key]; | 89 V value = _entries[key]; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 112 } | 112 } |
| 113 | 113 |
| 114 V remove(K key) => _entries.remove(key); | 114 V remove(K key) => _entries.remove(key); |
| 115 void removeAll() => _entries.clear(); | 115 void removeAll() => _entries.clear(); |
| 116 int get capacity => _capacity; | 116 int get capacity => _capacity; |
| 117 int get size => _entries.length; | 117 int get size => _entries.length; |
| 118 CacheStats stats() => new CacheStats(capacity, size, _hits, _misses); | 118 CacheStats stats() => new CacheStats(capacity, size, _hits, _misses); |
| 119 // Debugging helper. | 119 // Debugging helper. |
| 120 String toString() => "[$runtimeType: capacity=$capacity, size=$size, items=$_e
ntries]"; | 120 String toString() => "[$runtimeType: capacity=$capacity, size=$size, items=$_e
ntries]"; |
| 121 } | 121 } |
| OLD | NEW |