You've already forked redmine-bundle
made ttl configurable
This commit is contained in:
@@ -16,7 +16,8 @@ final class RedmineClient
|
|||||||
public function __construct(
|
public function __construct(
|
||||||
private TagAwareCacheInterface $cache,
|
private TagAwareCacheInterface $cache,
|
||||||
private string $url,
|
private string $url,
|
||||||
private string $apiKey
|
private string $apiKey,
|
||||||
|
private int $ttl
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function call(string $api, string $method, array $arguments = []): mixed
|
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)));
|
$cacheKey = sprintf('%s_%s_%s', $api, $method, sha1(serialize($arguments)));
|
||||||
|
|
||||||
return $this->cache->get($cacheKey, function (ItemInterface $item) use ($api, $method, $arguments): array {
|
return $this->cache->get($cacheKey, function (ItemInterface $item) use ($api, $method, $arguments): array {
|
||||||
$item->expiresAfter(3600);
|
$item->expiresAfter($this->ttl);
|
||||||
$item->tag([$api, $method]);
|
$item->tag([$api, $method]);
|
||||||
|
|
||||||
$client = $this->getClient()->getApi($api);
|
$client = $this->getClient()->getApi($api);
|
||||||
|
|||||||
@@ -14,26 +14,33 @@ final class Configuration implements ConfigurationInterface
|
|||||||
{
|
{
|
||||||
$treeBuilder = new TreeBuilder('magdev_redmine');
|
$treeBuilder = new TreeBuilder('magdev_redmine');
|
||||||
$rootNode = $treeBuilder->getRootNode();
|
$rootNode = $treeBuilder->getRootNode();
|
||||||
$rootNode->fixXmlConfig('connection')
|
$rootNode->children()
|
||||||
->children()
|
->scalarNode('ttl')
|
||||||
->arrayNode('connections')
|
->isRequired()
|
||||||
->useAttributeAsKey('name')
|
->info('TTL for cached api calls')
|
||||||
->normalizeKeys(false)
|
->end()
|
||||||
->arrayPrototype()
|
->end();
|
||||||
->children()
|
|
||||||
->scalarNode('url')
|
#$rootNode->fixXmlConfig('connection')
|
||||||
->isRequired()
|
# ->children()
|
||||||
->info('Base URL of the Redmine instance')
|
# ->arrayNode('connections')
|
||||||
->end()
|
# ->useAttributeAsKey('name')
|
||||||
->scalarNode('apikey')
|
# ->normalizeKeys(false)
|
||||||
->isRequired()
|
# ->arrayPrototype()
|
||||||
->info('Redmine API-Key')
|
# ->children()
|
||||||
->end()
|
# ->scalarNode('url')
|
||||||
->end()
|
# ->isRequired()
|
||||||
->end()
|
# ->info('Base URL of the Redmine instance')
|
||||||
->end()
|
# ->end()
|
||||||
->scalarNode('default_connection')->end()
|
# ->scalarNode('apikey')
|
||||||
;
|
# ->isRequired()
|
||||||
|
# ->info('Redmine API-Key')
|
||||||
|
# ->end()
|
||||||
|
# ->end()
|
||||||
|
# ->end()
|
||||||
|
# ->end()
|
||||||
|
# ->scalarNode('default_connection')->end()
|
||||||
|
#;
|
||||||
|
|
||||||
return $treeBuilder;
|
return $treeBuilder;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ final class MagdevRedmineExtension extends Extension
|
|||||||
{
|
{
|
||||||
$config = $this->processConfiguration(new Configuration(), $configs);
|
$config = $this->processConfiguration(new Configuration(), $configs);
|
||||||
|
|
||||||
|
$container->setParameter('magdev_redmine.ttl', $config['ttl']);
|
||||||
|
|
||||||
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||||
$loader->load('services.yaml');
|
$loader->load('services.yaml');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
services:
|
services:
|
||||||
Magdev\RedmineBundle\Client\RedmineClient:
|
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