@@ -83,6 +83,11 @@ class FileResolver {
83
83
84
84
_LibraryContext libraryContext;
85
85
86
+ /// List of ids for cache elements that are invalidated. Track elements that
87
+ /// are invalidated during [changeFile] . Used in [releaseAndClearRemovedIds] to
88
+ /// release the cache items and is then cleared.
89
+ final Set <int > removedCacheIds = {};
90
+
86
91
FileResolver (
87
92
PerformanceLog logger,
88
93
ResourceProvider resourceProvider,
@@ -132,7 +137,8 @@ class FileResolver {
132
137
/// Update the resolver to reflect the fact that the file with the given
133
138
/// [path] was changed. We need to make sure that when this file, of any file
134
139
/// that directly or indirectly referenced it, is resolved, we used the new
135
- /// state of the file.
140
+ /// state of the file. Updates [removedCacheIds] with the ids of the invalidated
141
+ /// items, used in [releaseAndClearRemovedIds] to release the cache items.
136
142
void changeFile (String path) {
137
143
if (fsState == null ) {
138
144
return ;
@@ -149,12 +155,13 @@ class FileResolver {
149
155
path: removedFile.path,
150
156
uri: removedFile.uri,
151
157
);
158
+ removedCacheIds.add (removedFile.id);
152
159
}
153
160
154
161
// Remove libraries represented by removed files.
155
162
// If we need these libraries later, we will relink and reattach them.
156
163
if (libraryContext != null ) {
157
- libraryContext.remove (removedFiles);
164
+ libraryContext.remove (removedFiles, removedCacheIds );
158
165
}
159
166
}
160
167
@@ -184,7 +191,7 @@ class FileResolver {
184
191
var errorsSignature = errorsSignatureBuilder.toByteList ();
185
192
186
193
var errorsKey = file.path + '.errors' ;
187
- var bytes = byteStore.get (errorsKey, errorsSignature);
194
+ var bytes = byteStore.get (errorsKey, errorsSignature)? .bytes ;
188
195
List <AnalysisError > errors;
189
196
if (bytes != null ) {
190
197
var data = CiderUnitErrors .fromBuffer (bytes);
@@ -204,7 +211,7 @@ class FileResolver {
204
211
signature: errorsSignature,
205
212
errors: errors.map (ErrorEncoding .encode).toList (),
206
213
).toBuffer ();
207
- byteStore.put (errorsKey, errorsSignature, bytes);
214
+ bytes = byteStore.putGet (errorsKey, errorsSignature, bytes).bytes ;
208
215
}
209
216
210
217
return ErrorsResultImpl (
@@ -314,6 +321,12 @@ class FileResolver {
314
321
_resetContextObjects ();
315
322
}
316
323
324
+ /// Update the cache with list of invalidated ids and clears [removedCacheIds] .
325
+ void releaseAndClearRemovedIds () {
326
+ byteStore.release (removedCacheIds);
327
+ removedCacheIds.clear ();
328
+ }
329
+
317
330
/// The [completionLine] and [completionColumn] are zero based.
318
331
ResolvedUnitResult resolve ({
319
332
int completionLine,
@@ -680,7 +693,8 @@ class _LibraryContext {
680
693
cycle.directDependencies.forEach (loadBundle);
681
694
682
695
var key = cycle.cyclePathsHash;
683
- var bytes = byteStore.get (key, cycle.signature);
696
+ var data = byteStore.get (key, cycle.signature);
697
+ var bytes = data? .bytes;
684
698
685
699
if (bytes == null ) {
686
700
librariesLinkedTimer.start ();
@@ -732,14 +746,16 @@ class _LibraryContext {
732
746
733
747
bytes = serializeBundle (cycle.signature, linkResult).toBuffer ();
734
748
735
- byteStore.put (key, cycle.signature, bytes);
749
+ data = byteStore.putGet (key, cycle.signature, bytes);
750
+ bytes = data.bytes;
736
751
performance.getDataInt ('bytesPut' ).add (bytes.length);
737
752
738
753
librariesLinkedTimer.stop ();
739
754
} else {
740
755
performance.getDataInt ('bytesGet' ).add (bytes.length);
741
756
performance.getDataInt ('libraryLoadCount' ).add (cycle.libraries.length);
742
757
}
758
+ cycle.id = data.id;
743
759
744
760
var cBundle = CiderLinkedLibraryCycle .fromBuffer (bytes);
745
761
inputBundles.add (cBundle.bundle);
@@ -775,14 +791,18 @@ class _LibraryContext {
775
791
776
792
/// Remove libraries represented by the [removed] files.
777
793
/// If we need these libraries later, we will relink and reattach them.
778
- void remove (List <FileState > removed) {
794
+ void remove (List <FileState > removed, Set < int > removedIds ) {
779
795
elementFactory.removeLibraries (
780
796
removed.map ((e) => e.uriStr).toSet (),
781
797
);
782
798
783
799
var removedSet = removed.toSet ();
784
800
loadedBundles.removeWhere ((cycle) {
785
- return cycle.libraries.any (removedSet.contains);
801
+ if (cycle.libraries.any (removedSet.contains)) {
802
+ removedIds.add (cycle.id);
803
+ return true ;
804
+ }
805
+ return false ;
786
806
});
787
807
}
788
808
0 commit comments