@@ -109,8 +109,8 @@ class DartToolDefinition extends ToolDefinition {
109109 assert (args[0 ] == command.first);
110110 // Set up flags to create a new snapshot, if needed, and use the first run
111111 // as the training run.
112- SnapshotCache .createInstance (_resourceProvider);
113- var snapshot = SnapshotCache .instance .getSnapshot (command.first);
112+ var snapshotCache = SnapshotCache .instanceFor (_resourceProvider);
113+ var snapshot = snapshotCache .getSnapshot (command.first);
114114 var snapshotFile = snapshot._snapshotFile;
115115 var snapshotPath =
116116 _resourceProvider.pathContext.absolute (snapshotFile.path);
@@ -212,11 +212,11 @@ class _Snapshot {
212212 void _snapshotCompleted () => _snapshotCompleter.complete ();
213213}
214214
215- /// A singleton that keeps track of cached snapshot files. The [dispose]
215+ /// A class that keeps track of cached snapshot files. The [dispose]
216216/// function must be called before process exit to clean up snapshots in the
217217/// cache.
218218class SnapshotCache {
219- static SnapshotCache _instance ;
219+ static final _instances = < ResourceProvider , SnapshotCache > {} ;
220220
221221 final Folder snapshotCache;
222222 final ResourceProvider _resourceProvider;
@@ -227,10 +227,12 @@ class SnapshotCache {
227227 : snapshotCache =
228228 _resourceProvider.createSystemTemp ('dartdoc_snapshot_cache_' );
229229
230- static SnapshotCache get instance => _instance;
231-
232- static SnapshotCache createInstance (ResourceProvider resourceProvider) =>
233- _instance ?? = SnapshotCache ._(resourceProvider);
230+ /// Returns a [SnapshotCache] for a given [ResourceProvider] , creating one
231+ /// only if one doesn't exist yet for the given [ResourceProvider] .
232+ factory SnapshotCache .instanceFor (ResourceProvider resourceProvider) {
233+ return _instances.putIfAbsent (
234+ resourceProvider, () => SnapshotCache ._(resourceProvider));
235+ }
234236
235237 _Snapshot getSnapshot (String toolPath) {
236238 if (snapshots.containsKey (toolPath)) {
@@ -243,7 +245,7 @@ class SnapshotCache {
243245 }
244246
245247 void dispose () {
246- _instance = null ;
248+ _instances. remove (_resourceProvider) ;
247249 if (snapshotCache != null && snapshotCache.exists) {
248250 return snapshotCache.delete ();
249251 }
0 commit comments