diff --git a/src/Client/RedmineClient.php b/src/Client/RedmineClient.php index 3b85418..a94c1f5 100644 --- a/src/Client/RedmineClient.php +++ b/src/Client/RedmineClient.php @@ -16,7 +16,8 @@ final class RedmineClient public function __construct( private TagAwareCacheInterface $cache, private string $url, - private string $apiKey + private string $apiKey, + private int $ttl ) {} public function call(string $api, string $method, array $arguments = []): mixed @@ -24,7 +25,7 @@ final class RedmineClient $cacheKey = sprintf('%s_%s_%s', $api, $method, sha1(serialize($arguments))); return $this->cache->get($cacheKey, function (ItemInterface $item) use ($api, $method, $arguments): array { - $item->expiresAfter(3600); + $item->expiresAfter($this->ttl); $item->tag([$api, $method]); $client = $this->getClient()->getApi($api); diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 6a664e4..b5240ba 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -14,26 +14,33 @@ final class Configuration implements ConfigurationInterface { $treeBuilder = new TreeBuilder('magdev_redmine'); $rootNode = $treeBuilder->getRootNode(); - $rootNode->fixXmlConfig('connection') - ->children() - ->arrayNode('connections') - ->useAttributeAsKey('name') - ->normalizeKeys(false) - ->arrayPrototype() - ->children() - ->scalarNode('url') - ->isRequired() - ->info('Base URL of the Redmine instance') - ->end() - ->scalarNode('apikey') - ->isRequired() - ->info('Redmine API-Key') - ->end() - ->end() - ->end() - ->end() - ->scalarNode('default_connection')->end() - ; + $rootNode->children() + ->scalarNode('ttl') + ->isRequired() + ->info('TTL for cached api calls') + ->end() + ->end(); + + #$rootNode->fixXmlConfig('connection') + # ->children() + # ->arrayNode('connections') + # ->useAttributeAsKey('name') + # ->normalizeKeys(false) + # ->arrayPrototype() + # ->children() + # ->scalarNode('url') + # ->isRequired() + # ->info('Base URL of the Redmine instance') + # ->end() + # ->scalarNode('apikey') + # ->isRequired() + # ->info('Redmine API-Key') + # ->end() + # ->end() + # ->end() + # ->end() + # ->scalarNode('default_connection')->end() + #; return $treeBuilder; } diff --git a/src/DependencyInjection/MagdevRedmineExtension.php b/src/DependencyInjection/MagdevRedmineExtension.php index 5765a76..6659583 100644 --- a/src/DependencyInjection/MagdevRedmineExtension.php +++ b/src/DependencyInjection/MagdevRedmineExtension.php @@ -17,6 +17,8 @@ final class MagdevRedmineExtension extends Extension { $config = $this->processConfiguration(new Configuration(), $configs); + $container->setParameter('magdev_redmine.ttl', $config['ttl']); + $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.yaml'); } diff --git a/src/Resources/config/services.yaml b/src/Resources/config/services.yaml index 09742a3..d39e98a 100644 --- a/src/Resources/config/services.yaml +++ b/src/Resources/config/services.yaml @@ -1,3 +1,3 @@ services: Magdev\RedmineBundle\Client\RedmineClient: - arguments: ['@redmine_api.cache', '%env(REDMINE_URL)%', '%env(REDMINE_APIKEY)%'] + arguments: ['@redmine_api.cache', '%env(REDMINE_URL)%', '%env(REDMINE_APIKEY)%', '%magdev_redmine.ttl%']