trying to get that cache thingi work

This commit is contained in:
2024-09-13 02:23:17 +02:00
parent b1452c4011
commit 6c608c5d00
2 changed files with 3 additions and 4 deletions

View File

@@ -6,7 +6,6 @@ use Redmine\Client\Psr18Client;
use GuzzleHttp\Client as GuzzleClient; use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Psr7\HttpFactory as GuzzleHttpFactory; use GuzzleHttp\Psr7\HttpFactory as GuzzleHttpFactory;
use Symfony\Contracts\Cache\TagAwareCacheInterface; use Symfony\Contracts\Cache\TagAwareCacheInterface;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
final class RedmineClient final class RedmineClient
{ {
@@ -15,8 +14,7 @@ final class RedmineClient
private ?string $apiKey = null; private ?string $apiKey = null;
public function __construct( public function __construct(
#[Autowire(service: 'redmine_api_cache_pool')] private TagAwareCacheInterface $cache
private TagAwareCacheInterface $redmineApiCachePool
) {} ) {}
public function setUrl(string $url): self public function setUrl(string $url): self
@@ -33,7 +31,7 @@ final class RedmineClient
{ {
$cacheKey = sprintf('%s_%s_%s', $api, $method, sha1(serialize($arguments))); $cacheKey = sprintf('%s_%s_%s', $api, $method, sha1(serialize($arguments)));
return $this->redmineApiCachePool->get($cacheKey, function (ItemInterface $item): string { return $this->cache->get($cacheKey, function (ItemInterface $item): string {
$item->expiresAfter(3600); $item->expiresAfter(3600);
$item->tag([$api, $method]); $item->tag([$api, $method]);

View File

@@ -25,6 +25,7 @@ final class MagdevRedmineExtension extends Extension
$container->register($id, RedmineClient::class) $container->register($id, RedmineClient::class)
->addMethodCall('setUrl', [$connection['url']]) ->addMethodCall('setUrl', [$connection['url']])
->addMethodCall('setApiKey', [$connection['apikey']]); ->addMethodCall('setApiKey', [$connection['apikey']]);
$container->registerAliasForArgument($id, RedmineClient::class, "{$name}Client"); $container->registerAliasForArgument($id, RedmineClient::class, "{$name}Client");
if ($name === $config['default_connection']) { if ($name === $config['default_connection']) {