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

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

Issue 1193993003: Add AnalysisCache.onResultInvalidated, use in DartWorkManager. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 6 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/lib/src/task/dart_work_manager.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 c8aa54d0c05cdc83f78c94ce33ed269cd901e764..0b93d03743b899c6b99864b1119d9b8443f2ab73 100644
--- a/pkg/analyzer/lib/src/context/cache.dart
+++ b/pkg/analyzer/lib/src/context/cache.dart
@@ -4,6 +4,7 @@
library analyzer.src.context.cache;
+import 'dart:async';
import 'dart:collection';
import 'package:analyzer/src/generated/engine.dart'
@@ -36,12 +37,30 @@ class AnalysisCache {
final List<CachePartition> _partitions;
/**
+ * The [StreamController] reporting [InvalidatedResult]s.
+ */
+ final StreamController<InvalidatedResult> _onResultInvalidated =
+ new StreamController<InvalidatedResult>.broadcast(sync: true);
+
+ /**
* Initialize a newly created cache to have the given [partitions]. The
* partitions will be searched in the order in which they appear in the array,
* so the most specific partition (usually an [SdkCachePartition]) should be
* first and the most general (usually a [UniversalCachePartition]) last.
*/
- AnalysisCache(this._partitions);
+ AnalysisCache(this._partitions) {
+ for (CachePartition partition in _partitions) {
+ partition.onResultInvalidated.listen((InvalidatedResult event) {
+ _onResultInvalidated.add(event);
+ });
+ }
+ }
+
+ /**
+ * Return the stream that is notified when a value is invalidated.
+ */
+ Stream<InvalidatedResult> get onResultInvalidated =>
+ _onResultInvalidated.stream;
// TODO(brianwilkerson) Implement or delete this.
// /**
@@ -500,6 +519,9 @@ class CacheEntry {
_partition._targetMap.remove(target);
_partition._removeIfSource(target);
}
+ // Notify controller.
+ _partition._onResultInvalidated
+ .add(new InvalidatedResult(this, descriptor));
}
/**
@@ -744,6 +766,12 @@ abstract class CachePartition {
new HashMap<ResultCachingPolicy, CacheFlushManager>();
/**
+ * The [StreamController] reporting [InvalidatedResult]s.
+ */
+ final StreamController<InvalidatedResult> _onResultInvalidated =
+ new StreamController<InvalidatedResult>.broadcast(sync: true);
+
+ /**
* A table mapping the targets belonging to this partition to the information
* known about those targets.
*/
@@ -776,6 +804,12 @@ abstract class CachePartition {
Map<AnalysisTarget, CacheEntry> get map => _targetMap;
/**
+ * Return the stream that is notified when a value is invalidated.
+ */
+ Stream<InvalidatedResult> get onResultInvalidated =>
+ _onResultInvalidated.stream;
+
+ /**
* Return the entry associated with the given [target].
*/
CacheEntry get(AnalysisTarget target) => _targetMap[target];
@@ -926,6 +960,26 @@ abstract class CachePartition {
}
/**
+ * [InvalidatedResult] describes an invalidated result.
+ */
+class InvalidatedResult {
+ /**
+ * The target in which the result was invalidated.
+ */
+ final CacheEntry entry;
+
+ /**
+ * The descriptor of the result which was invalidated.
+ */
+ final ResultDescriptor descriptor;
+
+ InvalidatedResult(this.entry, this.descriptor);
+
+ @override
+ String toString() => '$descriptor of ${entry.target}';
+}
+
+/**
* The data about a single analysis result that is stored in a [CacheEntry].
*/
// TODO(brianwilkerson) Consider making this a generic class so that the value
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/task/dart_work_manager.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698