For the first time I have set up a results cache in doctrine 1.24 by applying the following code:
$servers = array(
'host' => 'localhost',
'port' => 11211,
'persistent' => true
);
$cacheDriver = new Doctrine_Cache_Memcache(
array(
'servers' => $servers,
'compression' => false
)
);
$manager->setAttribute(Doctrine::ATTR_RESULT_CACHE,$cacheDriver);
$manager->setAttribute(Doctrine::ATTR_RESULT_CACHE_LIFESPAN, 3600 );
This works great for caching DQL quires such as:
enter code here$q = Doctrine_Query::create()
->from('Software s')
->leftJoin('s.Files f')
->useResultCache();
$q->execute();
However, What interests me is how do I cache table lookups such as:
xyzTable::getInstance()->findOneBySufff($stuff);
These are by far more frequent in my application code. How do I achieve this? Additionally, if anyone has a guide for using memcache with doctrine 1.2 I'd be more then happy.
You have to implement the
xyzTable::getInstance()->findOneBySufff($stuff);
functions in your own xyzTable class.
class xyzTable extends Doctrine_Table
{
public function findOneByStuff($stuff) {
return $this->createQuery('x')
->select('x.*')
->where('x.stuff = ?', $stuff)
->useResultCache()
->fetchOne();
}
}
Make sure you enable Table creation in your 'doctrine-cli' script
....
$doctrine_config['generate_models_options'] =
array('generateTableClasses' => true);
$cli = new Doctrine_Cli($doctrine_config);
....
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.