]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Repository/EntryRepository.php
Store cache lifetime in config
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Repository / EntryRepository.php
index b543c5ae3799e3b21fcbf5c382462bdccb269c02..4b205f6e52637ba69dfa8415815256aba5f875ea 100644 (file)
@@ -3,12 +3,15 @@
 namespace Wallabag\CoreBundle\Repository;
 
 use Doctrine\ORM\EntityRepository;
+use Doctrine\ORM\Query;
 use Pagerfanta\Adapter\DoctrineORMAdapter;
 use Pagerfanta\Pagerfanta;
 use Wallabag\CoreBundle\Entity\Tag;
 
 class EntryRepository extends EntityRepository
 {
+    private $lifeTime;
+
     /**
      * Return a query builder to used by other getBuilderFor* method.
      *
@@ -92,6 +95,8 @@ class EntryRepository extends EntityRepository
      * @param bool   $isStarred
      * @param string $sort
      * @param string $order
+     * @param int    $since
+     * @param string $tags
      *
      * @return array
      */
@@ -277,4 +282,25 @@ class EntryRepository extends EntityRepository
 
         return $qb->getQuery()->getSingleScalarResult();
     }
+
+    public function setLifeTime($lifeTime)
+    {
+        $this->lifeTime = $lifeTime;
+    }
+
+    /**
+     * Enable cache for a query.
+     *
+     * @param Query $query
+     *
+     * @return Query
+     */
+    public function enableCache(Query $query)
+    {
+        $query->useQueryCache(true);
+        $query->useResultCache(true);
+        $query->setResultCacheLifetime($this->lifeTime);
+
+        return $query;
+    }
 }