made ttl configurable

This commit is contained in:
2024-09-13 03:13:06 +02:00
parent a859a4a3ec
commit 30b61b5064
4 changed files with 33 additions and 23 deletions

View File

@@ -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);

View File

@@ -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')
$rootNode->children()
->scalarNode('ttl')
->isRequired()
->info('Base URL of the Redmine instance')
->info('TTL for cached api calls')
->end()
->scalarNode('apikey')
->isRequired()
->info('Redmine API-Key')
->end()
->end()
->end()
->end()
->scalarNode('default_connection')->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;
}

View File

@@ -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');
}

View File

@@ -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%']