简体   繁体   English

Yii CDbConnection缓存不起作用

[英]Yii CDbConnection cache not working

I am having an issue getting a specific query to cache properly. 我在获取特定查询以正确缓存时遇到问题。 Caching is working in other places in my app, so I think I have everything configured properly, but I cannot get this specific instance to work. 缓存正在我的应用程序的其他地方工作,因此我认为我已正确配置了所有内容,但无法使此特定实例正常工作。

My config 我的配置

'cache'=>array(
    'class'=>'system.caching.CFileCache',
    ),

Then, the code I am trying to execute: 然后,我尝试执行的代码:

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;

}

The sql is executed property, and returns as expected, it just never creates a cache entry and then never pulls from the cache. sql已执行属性,并按预期方式返回,它永远不会创建缓存条目,然后再从缓存中提取。

Anyone see anything I might be doing wrong here? 有人看到我在这里做错什么吗?

检查一下:

$connection = $connection->cache(18000);

您应该在查询行中应用缓存,如下所示:

$result = $command->cache(18000)->query();

暂无
暂无

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

相关问题 在Yii中重置CDbConnection - resetting CDbConnection in Yii Yii 中的 CDbConnection 错误 - CDbConnection error in Yii CDbConnection无法打开数据库连接Yii - CDbConnection failed to open the DB connection Yii yii CDbException:CDbConnection 无法打开数据库连接:找不到驱动程序 - yii CDbException: CDbConnection failed to open the DB connection: could not find driver CDbConnection无法打开数据库连接:在Yii中找不到驱动程序 - CDbConnection failed to open the DB connection: could not find driver in Yii 我想将 YII 框架与两个数据库连接,但它抛出 CDbConnection failed 数据库名称不正确 - I want to connect YII framework with two databases but it throws CDbConnection failed Incorrect database name Yii:当使用多个数据库时,如何使用租户设置来编辑从CDbConnection - Yii: How to edit a slave CDbConnection using the tennant settings when using multiple DBs Yii 1.1.x CDbHttpSession错误:CDbConnection无法打开数据库连接:找不到驱动程序 - Yii 1.1.x CDbHttpSession error: CDbConnection failed to open the DB connection: could not find driver CDbConnection无法打开数据库连接:在Yii中使用ORACLE数据库时找不到驱动程序 - CDbConnection failed to open the DB connection: could not find driver while using ORACLE database in Yii Yii CDbConnection无法打开数据库连接:找不到google cloud sql的驱动程序 - Yii CDbConnection failed to open the DB connection: could not find driver with google cloud sql
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM