Tuesday, October 18, 2011

Learn to Love the Cache

I've avoided using the caching aspects of Yii for a long time, simply because I never had time to dig into it. My cursory understanding was that you needed to have APC or memcached enabled on your server for it to work, and that wasn't something I could guarantee. That understanding was NOT correct.

There are several caching options built in to Yii, including a simple CFileCache which will write files to your application/runtime/cache/ folder and a CDummyCache that you can use if you need to bypass the real cache without altering your code.

This example starts with just the most basic situation where we are consuming data from an external source and caching it locally so that we do not continually ping the remote server for data.

The Guide to Caching can be found here: http://www.yiiframework.com/doc/guide/1.1/en/caching.overview