在我的 Symfony 5 应用程序中,我想为不同的任务使用不同的缓存,当然还有不同的环境。
例如,我的配置如下所示:
framework:
cache:
pools:
cache.auth:
adapter: cache.adapter.redis
provider: app.my_custom_redis_provider
cache.sap:
adapter: cache.adapter.redis
provider: app.my_custom_redis_provider
services:
app.my_custom_redis_provider:
arguments:
- '%env(REDIS_URL)%'
-
retry_interval: 2
timeout: '%env(REDIS_TIMEOUT)%'
class: Redis
factory:
- Symfony\Component\Cache\Adapter\RedisAdapter
- createConnection
我在我的类中使用依赖注入。那么我将如何定义特定类使用这两个缓存池中的哪一个呢?
目前我得到我的缓存是这样的:
class SapListService implements ListServiceInterface
{
use LoggerTrait;
private CountryServiceInterface $countryService;
private CurrencyServiceInterface $currencyService;
public function __construct(
SapClientFactoryInterface $sapClient,
CacheItemPoolInterface $cache,
ParameterBagInterface $params
) {
$sapUser = $params->get('sap_user');
$sapPw = $params->get('sap_pw');
$urlStruktur = $params->get('sap_struktur');
$this->countryService = $sapClient->getCountryService($sapUser, $sapPw, $urlStruktur, $cache);
$this->currencyService = $sapClient->getCurrencyService($sapUser, $sapPw, $urlStruktur, $cache);
}
如何配置我SapListService
以使用 cache.sap 池?