]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Store cache lifetime in config 2002/head
authorNicolas Lœuillet <nicolas@loeuillet.org>
Sat, 3 Sep 2016 12:02:50 +0000 (14:02 +0200)
committerNicolas Lœuillet <nicolas@loeuillet.org>
Sat, 3 Sep 2016 12:02:50 +0000 (14:02 +0200)
app/config/config.yml
app/config/config_dev.yml
src/Wallabag/CoreBundle/DependencyInjection/Configuration.php
src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php
src/Wallabag/CoreBundle/Repository/EntryRepository.php
src/Wallabag/CoreBundle/Resources/config/services.yml

index 807543930045daf6b6640963c76366dbe9fa4986..eb53fc5d45b5a819a08aa857c4f6237b6f5ce58d 100644 (file)
@@ -49,6 +49,7 @@ wallabag_core:
     language: en
     rss_limit: 50
     reading_speed: 1
+    cache_lifetime: 10
 
 wallabag_import:
     allow_mimetypes: ['application/octet-stream', 'application/json', 'text/plain']
index 77840682dfb273d0fac99a5d3ad40190e498ac59..3b67d8f6965b50a14b1460c9bea2a9416c25de8f 100644 (file)
@@ -40,3 +40,11 @@ swiftmailer:
     transport: smtp
     host: 'localhost'
     port: 1025
+
+# If you want to use cache for queries used in WallabagExtension
+# Uncomment the following lines
+#doctrine:
+#    orm:
+#        metadata_cache_driver: apcu
+#        result_cache_driver: apcu
+#        query_cache_driver: apcu
index d1bb9820beb3a4a498ca3a7b0b383a35e63e0683..d8141eea993ffbb277bf0954407ddeb2d774466e 100644 (file)
@@ -36,6 +36,9 @@ class Configuration implements ConfigurationInterface
                 ->end()
                 ->scalarNode('paypal_url')
                 ->end()
+                ->integerNode('cache_lifetime')
+                    ->defaultValue(10)
+                ->end()
             ->end()
         ;
 
index 7d08b73b78ceacf095e8c34a1ce61242e32f62d8..0cbde908d0f205f8a2f6e798316c18837866289e 100644 (file)
@@ -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');
index 86bce545e07ed7b14cfb037a2f23992ab4971274..4b205f6e52637ba69dfa8415815256aba5f875ea 100644 (file)
@@ -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;
     }
index f8835198caff7d55ffa12a9a5bf1bf64aef0be8f..b70d9b8cbb41466a025b78b654e3df47282ea85a 100644 (file)
@@ -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