After creating a record in manufacturer table, I try to clear the query cache which loads all manufacturers in a dropdown box, by using the following statement.
Yii::app()->db->schema->getTable('manufacturer', true);
But it is not clearing the cache created by the following query loading the dropdown box: The old manufacturers are still being displayed. The newly added manufacturer is not shown. In the log also, I verified that the cache was being used.
public function getAllManufacturers()
{
$sql = 'SELECT id, name FROM manufacturer WHERE store_id =:store_id ORDER BY name';
$cmd = Yii::app()->db->cache(72000)->createCommand($sql); //20 hours cache
$cmd->bindValue(':store_id', Yii::app()->session["current_store_id"], PDO::PARAM_INT);
return $cmd->queryAll();
}
View Call:
<?php echo $form->dropDownList($model,'manufacturer_id', CHtml::listData(Manufacturer::model()->getAllManufacturers(), 'id', 'name'), array('prompt'=>'Select Manufacturer')); ?>
However, the following stmt works, but it clears all query caches.
Yii::app()->cache->flush();
I am using memcache with schemaCachingDuration set to 72000 in db component
'cache' => array
(
'class' => 'CMemCache', // Use CApcCache, which is faster, if using a single server.
'servers'=>array(
array('host'=>'localhost', 'port'=>11211,),
),
),
'db'=>array
(
'connectionString' => 'mysql:host=localhost;dbname=storemgr',
'emulatePrepare' => true,
'schemaCachingDuration' => 72000, //20 hours
...
),