| 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:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/src/generated/engine.dart' | 9 import 'package:analyzer/src/generated/engine.dart' |
| 10 show AnalysisEngine, CacheState, InternalAnalysisContext, RetentionPriority; | 10 show AnalysisEngine, CacheState, InternalAnalysisContext, RetentionPriority; |
| (...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 */ | 650 */ |
| 651 List<TargetedResult> madeIdle() { | 651 List<TargetedResult> madeIdle() { |
| 652 maxSize = maxIdleSize; | 652 maxSize = maxIdleSize; |
| 653 return flushToSize(); | 653 return flushToSize(); |
| 654 } | 654 } |
| 655 | 655 |
| 656 /** | 656 /** |
| 657 * Records that the given [result] was just read from the cache. | 657 * Records that the given [result] was just read from the cache. |
| 658 */ | 658 */ |
| 659 void resultAccessed(TargetedResult result) { | 659 void resultAccessed(TargetedResult result) { |
| 660 if (maxSize <= 0) { |
| 661 return; |
| 662 } |
| 660 if (recentlyUsed.remove(result)) { | 663 if (recentlyUsed.remove(result)) { |
| 661 recentlyUsed.add(result); | 664 recentlyUsed.add(result); |
| 662 } | 665 } |
| 663 } | 666 } |
| 664 | 667 |
| 665 /** | 668 /** |
| 666 * Records that the given [newResult] and [newValue] were stored to the cache. | 669 * Records that the given [newResult] and [newValue] were stored to the cache. |
| 667 * Returns [TargetedResult]s that should be flushed from the cache. | 670 * Returns [TargetedResult]s that should be flushed from the cache. |
| 668 */ | 671 */ |
| 669 List<TargetedResult> resultStored(TargetedResult newResult, T newValue) { | 672 List<TargetedResult> resultStored(TargetedResult newResult, T newValue) { |
| 673 if (maxSize <= 0) { |
| 674 return TargetedResult.EMPTY_LIST; |
| 675 } |
| 670 if (!recentlyUsed.remove(newResult)) { | 676 if (!recentlyUsed.remove(newResult)) { |
| 671 int size = policy.measure(newValue); | 677 int size = policy.measure(newValue); |
| 672 resultSizeMap[newResult] = size; | 678 resultSizeMap[newResult] = size; |
| 673 currentSize += size; | 679 currentSize += size; |
| 674 } | 680 } |
| 675 recentlyUsed.add(newResult); | 681 recentlyUsed.add(newResult); |
| 676 return flushToSize(); | 682 return flushToSize(); |
| 677 } | 683 } |
| 678 | 684 |
| 679 /** | 685 /** |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 972 class UniversalCachePartition extends CachePartition { | 978 class UniversalCachePartition extends CachePartition { |
| 973 /** | 979 /** |
| 974 * Initialize a newly created cache partition, belonging to the given | 980 * Initialize a newly created cache partition, belonging to the given |
| 975 * [context]. | 981 * [context]. |
| 976 */ | 982 */ |
| 977 UniversalCachePartition(InternalAnalysisContext context) : super(context); | 983 UniversalCachePartition(InternalAnalysisContext context) : super(context); |
| 978 | 984 |
| 979 @override | 985 @override |
| 980 bool isResponsibleFor(AnalysisTarget target) => true; | 986 bool isResponsibleFor(AnalysisTarget target) => true; |
| 981 } | 987 } |
| OLD | NEW |