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 analyzer.src.context.cache; | 5 library analyzer.src.context.cache; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 | 9 |
10 import 'package:analyzer/file_system/file_system.dart'; | 10 import 'package:analyzer/file_system/file_system.dart'; |
(...skipping 922 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
933 /** | 933 /** |
934 * The current maximum cache size. | 934 * The current maximum cache size. |
935 */ | 935 */ |
936 int maxSize; | 936 int maxSize; |
937 | 937 |
938 CacheFlushManager( | 938 CacheFlushManager( |
939 ResultCachingPolicy<T> policy, this.isPriorityAnalysisTarget) | 939 ResultCachingPolicy<T> policy, this.isPriorityAnalysisTarget) |
940 : policy = policy, | 940 : policy = policy, |
941 maxActiveSize = policy.maxActiveSize, | 941 maxActiveSize = policy.maxActiveSize, |
942 maxIdleSize = policy.maxIdleSize, | 942 maxIdleSize = policy.maxIdleSize, |
943 maxSize = policy.maxIdleSize; | 943 maxSize = policy.maxActiveSize; |
944 | 944 |
945 /** | 945 /** |
946 * If [currentSize] is already less than [maxSize], returns an empty list. | 946 * If [currentSize] is already less than [maxSize], returns an empty list. |
947 * Otherwise returns [TargetedResult]s to flush from the cache to make | 947 * Otherwise returns [TargetedResult]s to flush from the cache to make |
948 * [currentSize] less or equal to [maxSize]. | 948 * [currentSize] less or equal to [maxSize]. |
949 * | 949 * |
950 * Results for priority files are never flushed, so this method might leave | 950 * Results for priority files are never flushed, so this method might leave |
951 * [currentSize] greater than [maxSize]. | 951 * [currentSize] greater than [maxSize]. |
952 */ | 952 */ |
953 List<TargetedResult> flushToSize() { | 953 List<TargetedResult> flushToSize() { |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1074 */ | 1074 */ |
1075 final Map<String, List<Source>> pathToSource = <String, List<Source>>{}; | 1075 final Map<String, List<Source>> pathToSource = <String, List<Source>>{}; |
1076 | 1076 |
1077 /** | 1077 /** |
1078 * Initialize a newly created cache partition, belonging to the given | 1078 * Initialize a newly created cache partition, belonging to the given |
1079 * [context]. | 1079 * [context]. |
1080 */ | 1080 */ |
1081 CachePartition(this.context); | 1081 CachePartition(this.context); |
1082 | 1082 |
1083 /** | 1083 /** |
| 1084 * Specify whether a context that uses this partition is being analyzed. |
| 1085 */ |
| 1086 set isActive(bool active) { |
| 1087 for (CacheFlushManager manager in _flushManagerMap.values) { |
| 1088 if (active) { |
| 1089 manager.madeActive(); |
| 1090 } else { |
| 1091 List<TargetedResult> resultsToFlush = manager.madeIdle(); |
| 1092 _flushResults(resultsToFlush); |
| 1093 } |
| 1094 } |
| 1095 } |
| 1096 |
| 1097 /** |
1084 * Notifies the partition that the client is going to stop using it. | 1098 * Notifies the partition that the client is going to stop using it. |
1085 */ | 1099 */ |
1086 void dispose() { | 1100 void dispose() { |
1087 for (CacheEntry entry in entryMap.values) { | 1101 for (CacheEntry entry in entryMap.values) { |
1088 entry.dispose(); | 1102 entry.dispose(); |
1089 } | 1103 } |
1090 entryMap.clear(); | 1104 entryMap.clear(); |
1091 sources.clear(); | 1105 sources.clear(); |
1092 pathToSource.clear(); | 1106 pathToSource.clear(); |
1093 } | 1107 } |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1169 flushManager.resultAccessed(result); | 1183 flushManager.resultAccessed(result); |
1170 } | 1184 } |
1171 | 1185 |
1172 /** | 1186 /** |
1173 * Records that the given [result] was just stored into the cache. | 1187 * Records that the given [result] was just stored into the cache. |
1174 */ | 1188 */ |
1175 void resultStored(TargetedResult result, Object value) { | 1189 void resultStored(TargetedResult result, Object value) { |
1176 CacheFlushManager flushManager = _getFlushManager(result.result); | 1190 CacheFlushManager flushManager = _getFlushManager(result.result); |
1177 List<TargetedResult> resultsToFlush = | 1191 List<TargetedResult> resultsToFlush = |
1178 flushManager.resultStored(result, value); | 1192 flushManager.resultStored(result, value); |
1179 for (TargetedResult result in resultsToFlush) { | 1193 _flushResults(resultsToFlush); |
1180 CacheEntry entry = get(result.target); | |
1181 if (entry != null) { | |
1182 ResultData data = entry._resultMap[result.result]; | |
1183 if (data != null) { | |
1184 data.flush(); | |
1185 } | |
1186 } | |
1187 } | |
1188 } | 1194 } |
1189 | 1195 |
1190 /** | 1196 /** |
1191 * Return the number of targets that are mapped to cache entries. | 1197 * Return the number of targets that are mapped to cache entries. |
1192 */ | 1198 */ |
1193 int size() => entryMap.length; | 1199 int size() => entryMap.length; |
1194 | 1200 |
1195 /** | 1201 /** |
1196 * If the given [target] is a [Source], adds it to [sources]. | 1202 * If the given [target] is a [Source], adds it to [sources]. |
1197 */ | 1203 */ |
1198 void _addIfSource(AnalysisTarget target) { | 1204 void _addIfSource(AnalysisTarget target) { |
1199 if (target is Source) { | 1205 if (target is Source) { |
1200 sources.add(target); | 1206 sources.add(target); |
1201 String fullName = target.fullName; | 1207 String fullName = target.fullName; |
1202 pathToSource.putIfAbsent(fullName, () => <Source>[]).add(target); | 1208 pathToSource.putIfAbsent(fullName, () => <Source>[]).add(target); |
1203 } | 1209 } |
1204 } | 1210 } |
1205 | 1211 |
1206 /** | 1212 /** |
| 1213 * Flush the given [resultsToFlush]. |
| 1214 */ |
| 1215 void _flushResults(List<TargetedResult> resultsToFlush) { |
| 1216 for (TargetedResult result in resultsToFlush) { |
| 1217 CacheEntry entry = get(result.target); |
| 1218 if (entry != null) { |
| 1219 ResultData data = entry._resultMap[result.result]; |
| 1220 if (data != null) { |
| 1221 data.flush(); |
| 1222 } |
| 1223 } |
| 1224 } |
| 1225 } |
| 1226 |
| 1227 /** |
1207 * Return the [CacheFlushManager] for the given [descriptor], not `null`. | 1228 * Return the [CacheFlushManager] for the given [descriptor], not `null`. |
1208 */ | 1229 */ |
1209 CacheFlushManager _getFlushManager(ResultDescriptor descriptor) { | 1230 CacheFlushManager _getFlushManager(ResultDescriptor descriptor) { |
1210 ResultCachingPolicy policy = descriptor.cachingPolicy; | 1231 ResultCachingPolicy policy = descriptor.cachingPolicy; |
1211 if (identical(policy, DEFAULT_CACHING_POLICY)) { | 1232 if (identical(policy, DEFAULT_CACHING_POLICY)) { |
1212 return UnlimitedCacheFlushManager.INSTANCE; | 1233 return UnlimitedCacheFlushManager.INSTANCE; |
1213 } | 1234 } |
1214 CacheFlushManager manager = _flushManagerMap[policy]; | 1235 CacheFlushManager manager = _flushManagerMap[policy]; |
1215 if (manager == null) { | 1236 if (manager == null) { |
1216 manager = new CacheFlushManager(policy, _isPriorityAnalysisTarget); | 1237 manager = new CacheFlushManager(policy, _isPriorityAnalysisTarget); |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1518 void resultAccessed(TargetedResult result) {} | 1539 void resultAccessed(TargetedResult result) {} |
1519 | 1540 |
1520 @override | 1541 @override |
1521 List<TargetedResult> resultStored(TargetedResult newResult, newValue) { | 1542 List<TargetedResult> resultStored(TargetedResult newResult, newValue) { |
1522 return TargetedResult.EMPTY_LIST; | 1543 return TargetedResult.EMPTY_LIST; |
1523 } | 1544 } |
1524 | 1545 |
1525 @override | 1546 @override |
1526 void targetRemoved(AnalysisTarget target) {} | 1547 void targetRemoved(AnalysisTarget target) {} |
1527 } | 1548 } |
OLD | NEW |