我通过在 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 字段,所以我如何实现对这个查询的依赖...