0

我通过在 main.php 文件中添加此代码在 php 中启用了 dbcache

 'cache'=>array(
            'class'=>'system.caching.CDbCache',
        'connectionID'=>'db',
        ),

现在我想定义此缓存的依赖关系以检查最后更新的记录,但我无法做到这一点。

查询是: -

public function actionProductList()
    {
        $model=new Product();
        $main=array();
        /* $random =Product::model()->find(array(
        'select'=>'MAX(update_time)',
        ));
        $dependency =new CDbCacheDependency($random);
        var_dump($random);*/
        $productList1=Product::model()->cache(60)->with('productimages')->findAll();
        foreach($productList1 as $productList)
        {
            $main1=array();
            foreach($productList->productimages as $list)
            {
                if($list->isProfileImage==1)
                {
            $main1[]=array("path"=>$list->path,"imageId"=>$list->imageId);
            }
            }
            if($productList->isPublish==1)
            {
                $main[]=array("productId"=>$productList->productId,"productName"=>$productList->productName,
                                "brandId"=>$productList->brandId,"mrp"=>$productList->mrp,
                                "isTaxInclude"=>$productList->isTaxInclude,"isAvailable"=>$productList->isAvailable,
                                "isFreeDelivery"=>$productList->isFreeDelivery,"description"=>$productList->description,
                                "isPublish"=>$productList->isPublish,"publishDate"=>$productList->publishDate,
                                "isActive"=>$productList->isActive,"userId"=>$productList->userId,
                                "createDate"=>$productList->createDate,"ipAddress"=>$productList->ipAddress,
                                "offerPrice"=>$productList->offerPrice,"manufactureId"=>$productList->manufactureId,"proimage"=>$main1);
        }
        }   
            echo"{\"Product\":".CJSON::encode($main)."}";

    }

而且我在产品表中没有 update_time 字段,所以我如何实现对这个查询的依赖...

4

1 回答 1

0

您应该解释您尝试过的内容以及您想要缓存的内容。手册中还有一个基本示例:

$dependency = new CDbCacheDependency('SELECT MAX(update_time) FROM tbl_post');
$posts = Post::model()->cache(1000, $dependency)->findAll();
于 2013-07-07T09:55:45.073 回答