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:io' as io; | 8 import 'dart:io' as io; |
9 | 9 |
10 import 'package:analyzer/file_system/file_system.dart'; | 10 import 'package:analyzer/file_system/file_system.dart'; |
11 import 'package:analyzer/source/package_map_provider.dart'; | 11 import 'package:analyzer/source/package_map_provider.dart'; |
12 import 'package:analyzer/source/pub_package_map_provider.dart'; | 12 import 'package:analyzer/source/pub_package_map_provider.dart'; |
13 import 'package:analyzer/src/generated/engine.dart'; | 13 import 'package:analyzer/src/generated/engine.dart'; |
14 import 'package:analyzer/src/generated/sdk_io.dart'; | 14 import 'package:analyzer/src/generated/sdk_io.dart'; |
15 import 'package:analyzer/src/generated/source.dart'; | 15 import 'package:analyzer/src/generated/source.dart'; |
16 | 16 |
17 /** | 17 /** |
18 * The function used to write the cache file. | 18 * The function used to write the cache file. |
19 * Returns the modification stamp for the newly written file. | 19 * Returns the modification stamp for the newly written file. |
20 */ | 20 */ |
21 typedef int WriteFile(File file, String content); | 21 typedef int WriteFile(File file, String content); |
22 | 22 |
23 /** | 23 /** |
24 * [PubPackageMapProvider] extension which caches pub list results. | 24 * [PubPackageMapProvider] extension which caches pub list results. |
25 * These results are cached in memory and in a single place on disk that is | 25 * These results are cached in memory and in a single place on disk that is |
26 * shared cross session and between different simultaneous sessions. | 26 * shared cross session and between different simultaneous sessions. |
| 27 * |
| 28 * TODO(paulberry): before this class is used again, it should be ported over |
| 29 * to extend OptimizingPubPackageMapProvider instead of PubPackageMapProvider. |
27 */ | 30 */ |
28 class CachingPubPackageMapProvider extends PubPackageMapProvider { | 31 class CachingPubPackageMapProvider extends PubPackageMapProvider { |
29 static const cacheKey = 'pub_list_cache'; | 32 static const cacheKey = 'pub_list_cache'; |
30 static const cacheVersion = 1; | 33 static const cacheVersion = 1; |
31 static const cacheVersionKey = 'pub_list_cache_version'; | 34 static const cacheVersionKey = 'pub_list_cache_version'; |
32 static const pubListResultKey = 'pub_list_result'; | 35 static const pubListResultKey = 'pub_list_result'; |
33 static const modificationStampsKey = 'modification_stamps'; | 36 static const modificationStampsKey = 'modification_stamps'; |
34 | 37 |
35 /** | 38 /** |
36 * A cache of folder path to pub list information as shown below | 39 * A cache of folder path to pub list information as shown below |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 // TODO(danrubel) This implementation assumes that | 249 // TODO(danrubel) This implementation assumes that |
247 // two separate processes are not accessing the cache file at the same time | 250 // two separate processes are not accessing the cache file at the same time |
248 io.File file = new io.File(cacheFile.path); | 251 io.File file = new io.File(cacheFile.path); |
249 if (!file.parent.existsSync()) { | 252 if (!file.parent.existsSync()) { |
250 file.parent.createSync(recursive: true); | 253 file.parent.createSync(recursive: true); |
251 } | 254 } |
252 file.writeAsStringSync(content, flush: true); | 255 file.writeAsStringSync(content, flush: true); |
253 return file.lastModifiedSync().millisecondsSinceEpoch; | 256 return file.lastModifiedSync().millisecondsSinceEpoch; |
254 } | 257 } |
255 } | 258 } |
OLD | NEW |