I am doing searching on product location and product type the results I want to cache the data.
How to cache the results?
public function actionMainsearch($rss = null){
$criteria = new CDbCriteria;
$criteria->addCondition('active = ' . Product::STATUS_ACTIVE);
$this->render('index', array(
'criteria' => $criteria,
'count' => $Count,
));
$location = Yii::app()->request->getPost('search_area');
$search_item = Yii::app()->request->getPost('search_item');
$search_item = preg_split('/[\ \,]+/', $search_item);
if(!count($search_item)) {
$search_item = array();
}
$location = preg_split('/[\ \,]+/',$location);
if(!count($location)) {
$location = array();
}
$attributes = Product::getSearchAttributes();
foreach($attributes as $attribute) {
foreach($search_item as $term) {
$criteria->addSearchCondition("LOWER($attribute)", strtolower($term), true, 'OR','LIKE');
}
}
$locattributes = Product::getLocationSearchAttributes();
foreach($locattributes as $attribute) {
foreach($loc as $term) {
$criteria->addSearchCondition("LOWER($attribute)", strtolower($term), true, 'OR','LIKE');
}
}
$criteria->with = array();
if(count($location)) {
$criteria->with = array_merge($criteria->with,array('city','country','state'));
}
if(count($search_item)) {
$criteria->with = array_merge($criteria->with,array('objType'));
}
$listingCount = Product::model()->count($criteria);
$this->render('index', array(
'criteria' => $criteria,
'count' => $listingCount,
));
}
How can I cache the search string and the results?