If I’m developing a site like a CMS with some dynamic structural elements, say the menu and certain orders of divs in the side bars, I’d like to have those items cached in a file since it’s fastest and most likely rarely going to change once the site has been made.
But other items like posts or comments and such that will change often I’d like to use some other caching method, like APC or memcache.
How can I configure multiple caching components used in different places?
Something to the effect of:
//cache something with file cache
//cache something with default mem cache
With the above config you can use:
All yii components that implement some kind of caching, have a $cacheID property.
For example CUrlManager::$cacheID. In this case you can set your second cache in config this way:
'components' => array(
'urlManager' => array(
'cacheID' => 'cache2',
There are many components that can be configured through config.
But there are other scenarios where you have to define the cacheID directly. Example:
if ($this->beginCache('example', array('cacheID' => 'cache2')))
By design every component uses ‘cache’ as the default cache component.
Awesome man, thanks.
I suppose as a follow up, would it be worth it? Caching more static items such as menus and page layouts with like file/APC and other stuff with something like memcache? Or would it be best to simply do everything with memcache?
I guess it could be used to use dedicated memcache servers for different parts of a large site, that could really be useful.