[英]Yii CDbConnection cache not working
我在获取特定查询以正确缓存时遇到问题。 缓存正在我的应用程序的其他地方工作,因此我认为我已正确配置了所有内容,但无法使此特定实例正常工作。
我的配置
'cache'=>array(
'class'=>'system.caching.CFileCache',
),
然后,我尝试执行的代码:
static public function getCities()
{
Yii::trace("Getting unique set of cities");
$sqlStatement = "select distinct city from mls_data where city <> '' order by city";
$connection = Yii::app()->db;
$connection->cache(18000);
$command= $connection->createCommand($sqlStatement);
// execute an SQL query and fetch the result set
$reader=$command->query();
// each $row is an array representing a row of data
foreach($reader as $row)
{
$returnArray[$row["city"]] = ucwords ( strtolower( substr($row["city"],0,17)));
}
return $returnArray;
}
sql已执行属性,并按预期方式返回,它永远不会创建缓存条目,然后再从缓存中提取。
有人看到我在这里做错什么吗?
检查一下:
$connection = $connection->cache(18000);
您应该在查询行中应用缓存,如下所示:
$result = $command->cache(18000)->query();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.