繁体   English   中英

如何使用查询/结果缓存(Doctrine 1.2)使Doctrine查找(如Doctrine_table-> find,-> findby *)

[英]How to make Doctrine lookups like Doctrine_table->find, ->findby* use the query/results cache (doctrine 1.2)

通过应用以下代码,我第一次在准则1.24中设置了结果缓存:

$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 );

这非常适合缓存DQL查询,例如:

enter code here$q = Doctrine_Query::create()
    ->from('Software s')
    ->leftJoin('s.Files f')
    ->useResultCache();
$q->execute();

但是,我感兴趣的是如何缓存表查找,例如:

xyzTable::getInstance()->findOneBySufff($stuff);

到目前为止,这些在我的应用程序代码中更为常见。 我该如何实现? 此外,如果有人对在准则1.2中使用Memcache有了指导,我会更高兴。

您必须实施

xyzTable::getInstance()->findOneBySufff($stuff);

您自己的xyzTable类中的函数。

class xyzTable extends Doctrine_Table 
{
     public function findOneByStuff($stuff) {
         return $this->createQuery('x')
              ->select('x.*')
              ->where('x.stuff = ?', $stuff)
              ->useResultCache()
              ->fetchOne();

     }
}

确保在“ doctrine-cli”脚本中启用表创建

 ....
 $doctrine_config['generate_models_options'] = 
    array('generateTableClasses' => true);

 $cli = new Doctrine_Cli($doctrine_config);
 ....

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM