Reputation: 6277
But i'm new to the caching technique. After reading docs (and following), and some examples i still of little clue how to use it.
I need to apply caching for the CMS/CRM site we developed. The application/website is a mix of web shop and client order processing, how to make it optimized? What cache components is optimal to use?
The typical user request (the main concern for caching) would be to assortment/goods grid page with ability to filter goods by category, make, manufacturer, article and so on.
My concept is that it's not possible to predict each user's behaviour as to what kind of options/filters he'll impose on given data. So how could caching be applied? Please, correct me if it's not so. Users might be logged in or not.
I've set in main.php the cache
setting in components:
'components'=>array(
'cache'=>array(
'class'=>'system.caching.COutputCache',
'connectionID'=>'db',
'autoCreateCacheTable'=>false,
'cacheTableName'=>'cache',
),
...
I've added caching setting into filters()
of AssortmentController
:
public function filters()
{
return array(
'accessControl', // perform access control for CRUD operations
'postOnly + delete', // we only allow deletion via POST request
array(
'COutputCache',
'duration'=>1000,
'varyByParam'=>array('id'),
),
);
}
beginCache
and endCache
somewhere in view file or in layout file, where if so? But still there might be more GET parameters (apart from id
) like Assortment[title], Assortment[article] , Assortment[groupCategory]?
Should i add them as well?
'varyByParam'=>array('id', 'Assortment[title]', 'Assortment[article]' , 'Assortment[groupCategory]')
Any corrections, docs' links, guidelines would be appreciable.
Upvotes: 0
Views: 145
Reputation: 342
To create cache for particular views add this: 'COutputCache + view', (this means only 'view' action will be cached)
You may use multiple Cache either by defining a cacheId and referring it to it in beginCache $this->beginCache('name', array('cacheID' => 'filecache')).
COutputCache is referred here (http://www.yiiframework.com/doc/api/1.1/COutputCache).
Only the params inside the varyByParams will be considered for cache key. /products/view/1/some/param AND /products/view/1/another/param will be served from the same cache
If you have additional params that will add / be part of the caching you need to add them.
Upvotes: 1