From b3f4a11a81b520b8dcc2bcebeeafea2cc0338a70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Sat, 3 Sep 2016 14:02:50 +0200 Subject: Store cache lifetime in config --- src/Wallabag/CoreBundle/DependencyInjection/Configuration.php | 3 +++ .../CoreBundle/DependencyInjection/WallabagCoreExtension.php | 1 + src/Wallabag/CoreBundle/Repository/EntryRepository.php | 11 +++++++++-- src/Wallabag/CoreBundle/Resources/config/services.yml | 2 ++ 4 files changed, 15 insertions(+), 2 deletions(-) (limited to 'src/Wallabag/CoreBundle') diff --git a/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php b/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php index d1bb9820..d8141eea 100644 --- a/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php +++ b/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php @@ -36,6 +36,9 @@ class Configuration implements ConfigurationInterface ->end() ->scalarNode('paypal_url') ->end() + ->integerNode('cache_lifetime') + ->defaultValue(10) + ->end() ->end() ; diff --git a/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php b/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php index 7d08b73b..0cbde908 100644 --- a/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php +++ b/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php @@ -22,6 +22,7 @@ class WallabagCoreExtension extends Extension $container->setParameter('wallabag_core.reading_speed', $config['reading_speed']); $container->setParameter('wallabag_core.version', $config['version']); $container->setParameter('wallabag_core.paypal_url', $config['paypal_url']); + $container->setParameter('wallabag_core.cache_lifetime', $config['cache_lifetime']); $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.yml'); diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index 86bce545..4b205f6e 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -10,6 +10,8 @@ use Wallabag\CoreBundle\Entity\Tag; class EntryRepository extends EntityRepository { + private $lifeTime; + /** * Return a query builder to used by other getBuilderFor* method. * @@ -281,8 +283,13 @@ class EntryRepository extends EntityRepository return $qb->getQuery()->getSingleScalarResult(); } + public function setLifeTime($lifeTime) + { + $this->lifeTime = $lifeTime; + } + /** - * Enable cache for a query + * Enable cache for a query. * * @param Query $query * @@ -292,7 +299,7 @@ class EntryRepository extends EntityRepository { $query->useQueryCache(true); $query->useResultCache(true); - $query->setResultCacheLifetime(5); + $query->setResultCacheLifetime($this->lifeTime); return $query; } diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml index f8835198..b70d9b8c 100644 --- a/src/Wallabag/CoreBundle/Resources/config/services.yml +++ b/src/Wallabag/CoreBundle/Resources/config/services.yml @@ -81,6 +81,8 @@ services: factory: [ "@doctrine.orm.default_entity_manager", getRepository ] arguments: - WallabagCoreBundle:Entry + calls: + - [ setLifeTime, [ "%wallabag_core.cache_lifetime%" ] ] wallabag_core.tag_repository: class: Wallabag\CoreBundle\Repository\TagRepository -- cgit v1.2.3