Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(612)

Unified Diff: pkg/analyzer/lib/src/context/cache.dart

Issue 1151193002: Use UnlimitedCacheFlushManager for DEFAULT_CACHING_POLICY. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/src/context/cache_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/context/cache.dart
diff --git a/pkg/analyzer/lib/src/context/cache.dart b/pkg/analyzer/lib/src/context/cache.dart
index fc188ba1ec20ce9f7213c8b3c7536cac67adc211..eab096f197a30691d8982b61e2b6dff67ad5b364 100644
--- a/pkg/analyzer/lib/src/context/cache.dart
+++ b/pkg/analyzer/lib/src/context/cache.dart
@@ -12,6 +12,7 @@ import 'package:analyzer/src/generated/java_engine.dart';
import 'package:analyzer/src/generated/source.dart';
import 'package:analyzer/src/generated/utilities_collection.dart';
import 'package:analyzer/src/generated/utilities_general.dart';
+import 'package:analyzer/src/task/model.dart';
import 'package:analyzer/task/model.dart';
/**
@@ -616,7 +617,7 @@ class CacheFlushManager<T> {
*/
List<TargetedResult> flushToSize() {
// If still under the cap, done.
- if (maxSize == -1 || currentSize <= maxSize) {
+ if (currentSize <= maxSize) {
return TargetedResult.EMPTY_LIST;
}
// Flush results until we are under the cap.
@@ -657,9 +658,6 @@ class CacheFlushManager<T> {
* Records that the given [result] was just read from the cache.
*/
void resultAccessed(TargetedResult result) {
- if (maxSize <= 0) {
- return;
- }
if (recentlyUsed.remove(result)) {
recentlyUsed.add(result);
}
@@ -670,9 +668,6 @@ class CacheFlushManager<T> {
* Returns [TargetedResult]s that should be flushed from the cache.
*/
List<TargetedResult> resultStored(TargetedResult newResult, T newValue) {
- if (maxSize <= 0) {
- return TargetedResult.EMPTY_LIST;
- }
if (!recentlyUsed.remove(newResult)) {
int size = policy.measure(newValue);
resultSizeMap[newResult] = size;
@@ -844,8 +839,15 @@ abstract class CachePartition {
*/
CacheFlushManager _getFlushManager(ResultDescriptor descriptor) {
ResultCachingPolicy policy = descriptor.cachingPolicy;
- return _flushManagerMap.putIfAbsent(
- policy, () => new CacheFlushManager(policy, _isPriorityAnalysisTarget));
+ if (identical(policy, DEFAULT_CACHING_POLICY)) {
+ return UnlimitedCacheFlushManager.INSTANCE;
+ }
+ CacheFlushManager manager = _flushManagerMap[policy];
+ if (manager == null) {
+ manager = new CacheFlushManager(policy, _isPriorityAnalysisTarget);
+ _flushManagerMap[policy] = manager;
+ }
+ return manager;
}
bool _isPriorityAnalysisTarget(AnalysisTarget target) {
@@ -985,3 +987,23 @@ class UniversalCachePartition extends CachePartition {
@override
bool isResponsibleFor(AnalysisTarget target) => true;
}
+
+/**
+ * [CacheFlushManager] that does nothing, results are never flushed.
+ */
+class UnlimitedCacheFlushManager extends CacheFlushManager {
+ static final CacheFlushManager INSTANCE = new UnlimitedCacheFlushManager();
+
+ UnlimitedCacheFlushManager() : super(DEFAULT_CACHING_POLICY, (_) => false);
+
+ @override
+ void resultAccessed(TargetedResult result) {}
+
+ @override
+ List<TargetedResult> resultStored(TargetedResult newResult, newValue) {
+ return TargetedResult.EMPTY_LIST;
+ }
+
+ @override
+ void targetRemoved(AnalysisTarget target) {}
+}
« no previous file with comments | « no previous file | pkg/analyzer/test/src/context/cache_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698