Doctrine creates a connection to the database even if the result is cached

94 Views Asked by At

In my EntityRepository :

public function findFirst()
{
    $qb = $this->createQueryBuilder('a');
      $qb
        ->orderBy('a.id')
        ->setMaxResults(4)
        ->where('a.valided = true')
        ->leftJoin('a.reponses', 'r')
        ->addSelect('r')
    ;
    $query = $qb->getQuery();

    $query->useQueryCache(true);
    $query->useResultCache(true);
    $query->setResultCacheLifetime(2678400); // One month
    $query->setCacheable(true);

    return $query->getSingleResult();
}

When getSingleResult() is executed, doctrine creates a database connexion. However, the result is already cached : it will no execute request.

This is a waste of resources.

Any idea ? Thank you !

0

There are 0 best solutions below