| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of service; | 5 part of service; |
| 6 | 6 |
| 7 /// Abstract [ServiceObjectCache]. | 7 /// Abstract [ServiceObjectCache]. |
| 8 abstract class ServiceObjectCache<T extends ServiceObject> { | 8 abstract class ServiceObjectCache<T extends ServiceObject> { |
| 9 final Isolate isolate; | 9 final Isolate isolate; |
| 10 final _cache = new ObservableMap<String, T>(); | 10 final _cache = new ObservableMap<String, T>(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 operator[]=(String id, T serviceObject) { | 35 operator[]=(String id, T serviceObject) { |
| 36 assert(cachesId(id)); | 36 assert(cachesId(id)); |
| 37 _cache[id] = serviceObject; | 37 _cache[id] = serviceObject; |
| 38 } | 38 } |
| 39 | 39 |
| 40 /// Gets [id] from the cache or makes a network request for [id]. | 40 /// Gets [id] from the cache or makes a network request for [id]. |
| 41 Future<T> get(String id) { | 41 Future<T> get(String id) { |
| 42 assert(cachesId(id)); | 42 assert(cachesId(id)); |
| 43 T cached = _cache[id]; | 43 T cached = _cache[id]; |
| 44 if (cached != null) { | 44 if (cached != null) { |
| 45 return new Future.value(cached); | 45 return cached.load(); |
| 46 } | 46 } |
| 47 return isolate.get(id).then(_addToCache); | 47 return isolate.getDirect(id); |
| 48 } | 48 } |
| 49 | 49 |
| 50 /// If [obj] is cached, return the cached object. Otherwise, upgrades [obj] | 50 /// If [obj] is cached, return the cached object. Otherwise, upgrades [obj] |
| 51 /// and adds the upgraded value to the cache. | 51 /// and adds the upgraded value to the cache. |
| 52 T putIfAbsent(ObservableMap obj) { | 52 T putIfAbsent(ObservableMap obj) { |
| 53 assert(ServiceObject.isServiceMap(obj)); | 53 assert(ServiceObject.isServiceMap(obj)); |
| 54 String id = obj['id']; | 54 String id = obj['id']; |
| 55 var type = obj['type']; | 55 var type = obj['type']; |
| 56 if (!cachesId(id)) { | 56 if (!cachesId(id)) { |
| 57 Logger.root.warning('Cache does not cache this id: $id'); | 57 Logger.root.warning('Cache does not cache this id: $id'); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 static final RegExp _matcher = | 152 static final RegExp _matcher = |
| 153 new RegExp(r'^functions/native-.+|' | 153 new RegExp(r'^functions/native-.+|' |
| 154 r'^functions/collected-.+|' | 154 r'^functions/collected-.+|' |
| 155 r'^functions/reused-.+|' | 155 r'^functions/reused-.+|' |
| 156 r'^functions/stub-.+|' | 156 r'^functions/stub-.+|' |
| 157 r'^classes/\d+/functions/.+|' | 157 r'^classes/\d+/functions/.+|' |
| 158 r'^classes/\d+/closures/.+|' | 158 r'^classes/\d+/closures/.+|' |
| 159 r'^classes/\d+/implicit_closures/.+|' | 159 r'^classes/\d+/implicit_closures/.+|' |
| 160 r'^classes/\d+/dispatchers/.+'); | 160 r'^classes/\d+/dispatchers/.+'); |
| 161 } | 161 } |
| OLD | NEW |