| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library source.caching_pub_package_map_provider; | 5 library source.caching_pub_package_map_provider; |
| 6 | 6 |
| 7 import 'dart:convert'; | 7 import 'dart:convert'; |
| 8 import 'dart:core' hide Resource; | 8 import 'dart:core' hide Resource; |
| 9 import 'dart:io' as io; | 9 import 'dart:io' as io; |
| 10 | 10 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 // cached result because folder may be only temporarily inaccessible | 99 // cached result because folder may be only temporarily inaccessible |
| 100 // | 100 // |
| 101 if (!folder.exists) { | 101 if (!folder.exists) { |
| 102 return computePackageMapError(folder); | 102 return computePackageMapError(folder); |
| 103 } | 103 } |
| 104 // Ensure cache is up to date | 104 // Ensure cache is up to date |
| 105 _readCache(); | 105 _readCache(); |
| 106 // Check for cached entry | 106 // Check for cached entry |
| 107 Map entry = _cache[folder.path]; | 107 Map entry = _cache[folder.path]; |
| 108 if (entry != null) { | 108 if (entry != null) { |
| 109 Map<String, int> modificationStamps = entry[modificationStampsKey]; | 109 Map<String, int> modificationStamps = |
| 110 entry[modificationStampsKey] as Map<String, int>; |
| 110 if (modificationStamps != null) { | 111 if (modificationStamps != null) { |
| 111 // | 112 // |
| 112 // Check to see if any dependencies have changed | 113 // Check to see if any dependencies have changed |
| 113 // before returning cached result | 114 // before returning cached result |
| 114 // | 115 // |
| 115 if (!_haveDependenciesChanged(modificationStamps)) { | 116 if (!_haveDependenciesChanged(modificationStamps)) { |
| 116 return parsePackageMap(entry[pubListResultKey], folder); | 117 return parsePackageMap(entry[pubListResultKey], folder); |
| 117 } | 118 } |
| 118 } | 119 } |
| 119 } | 120 } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 // TODO(danrubel) This implementation assumes that | 211 // TODO(danrubel) This implementation assumes that |
| 211 // two separate processes are not accessing the cache file at the same time | 212 // two separate processes are not accessing the cache file at the same time |
| 212 Source source = cacheFile.createSource(); | 213 Source source = cacheFile.createSource(); |
| 213 if (source.exists() && | 214 if (source.exists() && |
| 214 (_cache == null || | 215 (_cache == null || |
| 215 _cacheModificationTime != source.modificationStamp)) { | 216 _cacheModificationTime != source.modificationStamp)) { |
| 216 try { | 217 try { |
| 217 TimestampedData<String> data = source.contents; | 218 TimestampedData<String> data = source.contents; |
| 218 Map map = JSON.decode(data.data); | 219 Map map = JSON.decode(data.data); |
| 219 if (map[cacheVersionKey] == cacheVersion) { | 220 if (map[cacheVersionKey] == cacheVersion) { |
| 220 _cache = map[cacheKey]; | 221 _cache = map[cacheKey] as Map<String, Map>; |
| 221 _cacheModificationTime = data.modificationTime; | 222 _cacheModificationTime = data.modificationTime; |
| 222 } | 223 } |
| 223 } catch (exception, stackTrace) { | 224 } catch (exception, stackTrace) { |
| 224 AnalysisEngine.instance.logger.logInformation( | 225 AnalysisEngine.instance.logger.logInformation( |
| 225 'Exception reading $cacheFile\n$exception\n$stackTrace'); | 226 'Exception reading $cacheFile\n$exception\n$stackTrace'); |
| 226 } | 227 } |
| 227 } | 228 } |
| 228 if (_cache == null) { | 229 if (_cache == null) { |
| 229 _cache = new Map<String, Map>(); | 230 _cache = new Map<String, Map>(); |
| 230 } | 231 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 250 // TODO(danrubel) This implementation assumes that | 251 // TODO(danrubel) This implementation assumes that |
| 251 // two separate processes are not accessing the cache file at the same time | 252 // two separate processes are not accessing the cache file at the same time |
| 252 io.File file = new io.File(cacheFile.path); | 253 io.File file = new io.File(cacheFile.path); |
| 253 if (!file.parent.existsSync()) { | 254 if (!file.parent.existsSync()) { |
| 254 file.parent.createSync(recursive: true); | 255 file.parent.createSync(recursive: true); |
| 255 } | 256 } |
| 256 file.writeAsStringSync(content, flush: true); | 257 file.writeAsStringSync(content, flush: true); |
| 257 return file.lastModifiedSync().millisecondsSinceEpoch; | 258 return file.lastModifiedSync().millisecondsSinceEpoch; |
| 258 } | 259 } |
| 259 } | 260 } |
| OLD | NEW |