php - Doctrine cache relations -
i have entity 'category' has relation many 'projects' in term has many 'images'.
i'm caching results inside 'category' repository fetch project linked category conditions. caching done redisbundle , doctrine: query->setresultcachedriver functions:
try { $qb = $this->getentitymanager()->createquerybuilder(); $qb->select('category', 'projects') ->from('appbundle\entity\category', 'category') ->leftjoin( 'category.projects', 'projects', \doctrine\orm\query\expr\join::with, $qb->expr()->eq('projects.active', 1) ) ->where( $qb->expr()->eq('category.slug', ':slug') ) ->setparameter('slug', $slug); $query = $qb->getquery(); $query ->setresultcachedriver($this->cachedriver) ->setresultcachelifetime($this->cachelifetime); return $query->getoneornullresult(); } catch (\doctrine\orm\noresultexception $e) { return null; }
i'm looping throught projects in view , display imags of each project.
is possible cache queries to? im getting 1 query each project fetch images.
what you're doing cache isn't issue. reason you're getting image query per category because you're lazy loading images. left join images categories , add images select , you're good.
Comments
Post a Comment