29 lines
662 B
PHP
29 lines
662 B
PHP
<?php
|
|
|
|
namespace Modules\EcommerceFinance\Services;
|
|
|
|
use Illuminate\Cache\CacheManager;
|
|
|
|
class UpstreamQueryCacheFactory
|
|
{
|
|
/** @var array<string,UpstreamQueryCache> */
|
|
private array $instances = [];
|
|
|
|
public function __construct(
|
|
private readonly UpstreamSourceRegistry $sources,
|
|
private readonly CacheManager $cacheManager,
|
|
) {
|
|
}
|
|
|
|
public function forSource(string $source): UpstreamQueryCache
|
|
{
|
|
$key = $this->sources->definition($source)['key'];
|
|
|
|
return $this->instances[$key] ??= new UpstreamQueryCache(
|
|
$this->sources,
|
|
$key,
|
|
$this->cacheManager
|
|
);
|
|
}
|
|
}
|