*/ private array $instances = []; /** @var array */ private array $timedInstances = []; public function __construct(private readonly UpstreamSourceRegistry $sources) { } public function forSource(string $source): UpstreamReadOnlyQuery { $key = $this->sources->definition($source)['key']; return $this->instances[$key] ??= new UpstreamReadOnlyQuery($key); } public function forSourceWithTimeout(string $source, int $timeoutSeconds): UpstreamReadOnlyQuery { $key = $this->sources->definition($source)['key']; $timeoutSeconds = max(1, min($timeoutSeconds, 120)); $cacheKey = $key . '@' . $timeoutSeconds; return $this->timedInstances[$cacheKey] ??= new UpstreamReadOnlyQuery($key, $timeoutSeconds); } }