I decided to use LswMemcacheBundle (in Symfony2) to cache Doctrine2 queries into memcached, but I've got one problem. I can't find any information about possibility to change cache life time, even about default life time.
Is there anyone who can provide me such informations?
It looks like results cache is not enabled for all queries (but query cache is enabled) and we need to enable it using useResultCache method. This method also allows us to set cache life time.
So it'll look like this
$em->createQuery('SELECT a FROM SomeBundle:Entity a')
->useResultCache(true, 3600, 'cacheId')
->getResult();
and for createQueryBuilder
$repository = $this->getEntityManager()->getRepository('SomeBundle:Entity');
$qb = $repository->createQueryBuilder('g');
$qb->andWhere('g.categoryId = :categoryId')->setParameter('categoryId', '1');
$qb->addOrderBy('g.id', 'DESC');
$query = $qb->getQuery();
$query->useResultCache(true, 3600, 'cacheId');
where 3600 will be cache life time in seconds and cacheId our cache key.
I think that you still have to set the cache lifetime using the methods through the cacheDriver.
http://docs.doctrine-project.org/en/2.0.x/reference/caching.html#result-cache
http://docs.doctrine-project.org/en/2.0.x/reference/caching.html#saving
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With