Skip to content

Commit ffb9838

Browse files
committed
ServiceLocator.storageInstanceManager is class-level
1 parent 2f6f9bc commit ffb9838

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

packages/core/src/service_locator.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,10 @@ export class ServiceLocator implements ServiceLocatorInterface {
135135

136136
/**
137137
* Unified storage instance manager for Dataset, KeyValueStore, and RequestQueue.
138-
* Manages caching and lifecycle of storage instances.
138+
* Shared across all ServiceLocator instances (global singleton), matching crawlee-python.
139+
* Per-crawler isolation is achieved via `clientCacheKey`, not separate manager instances.
139140
*/
140-
private storageInstanceManager?: StorageInstanceManager;
141+
private static storageInstanceManager?: StorageInstanceManager;
141142

142143
/**
143144
* Creates a new ServiceLocator instance.
@@ -265,23 +266,23 @@ export class ServiceLocator implements ServiceLocatorInterface {
265266
}
266267

267268
getStorageInstanceManager(): StorageInstanceManager {
268-
if (!this.storageInstanceManager) {
269-
this.storageInstanceManager = new StorageInstanceManager(this.getConfiguration());
269+
if (!ServiceLocator.storageInstanceManager) {
270+
ServiceLocator.storageInstanceManager = new StorageInstanceManager(this.getConfiguration());
270271
}
271-
return this.storageInstanceManager;
272+
return ServiceLocator.storageInstanceManager;
272273
}
273274

274275
clearStorageManagerCache(): void {
275-
if (this.storageInstanceManager) {
276+
if (ServiceLocator.storageInstanceManager) {
276277
// KeyValueStore instances have a clearCache method — call it on any cached
277278
// instance that exposes it, without importing KeyValueStore (avoids circular deps).
278-
for (const instance of this.storageInstanceManager.getAllInstances()) {
279+
for (const instance of ServiceLocator.storageInstanceManager.getAllInstances()) {
279280
if ('clearCache' in instance && typeof (instance as any).clearCache === 'function') {
280281
(instance as any).clearCache();
281282
}
282283
}
283284

284-
this.storageInstanceManager.clearCache();
285+
ServiceLocator.storageInstanceManager.clearCache();
285286
}
286287
}
287288

@@ -291,7 +292,7 @@ export class ServiceLocator implements ServiceLocatorInterface {
291292
this.storageClient = undefined;
292293
this.logger = undefined;
293294
this.clearStorageManagerCache();
294-
this.storageInstanceManager = undefined;
295+
ServiceLocator.storageInstanceManager = undefined;
295296
}
296297
}
297298

0 commit comments

Comments
 (0)