How to cache doctrine "findOneBy()" query with cache id and cache lifetime option in Symfony 2.4?
caching, doctrine-orm, php, symfony
Solution
You need to redefine every findBy* or findOneBy* function into custom repository: this is the only way as doctrine2 default behaviour doesn't take into account this situation. Is up to you, unfortunately.
Also Ocramius (a Doctrine2 devel) say it here https://groups.google.com/d/msg/doctrine-user/RIeH8ZkKyEY/HnR7h2p0lCQJ
Problem
I am working on the symfony 2.5 project with doctrine 2.4. I want to cache query result with cache id and cache time, so I can delete the cache result, whenever needed though admin. I am able to cache the query result with "createQueryBuilder()" option. Example: ``` $this->createQueryBuilder('some_table') ->select('some_table') ->where('some_table.deleted_date IS NULL') ->getQuery() ->useResultCache(true) ->setResultCacheLifetime(120) //Query Cache lifetime ->setResultCacheId($queryCacheId) //Query Cache Id ->getResult(); ``` But I am not able to find the similar way to chache query result for "findOneBy()" option. Example: ``` $this->findOneBy(array('some_field'=>$some_value)); ``` I am looking some proper solution, any help is much appreciated.