You've already forked redmine-bundle
made ttl configurable
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
@@ -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%']
|
||||
|
||||
Reference in New Issue
Block a user