What is the best caching method offered by Yii ?


I have seen that there is a lot of caching components offered by Yii, but i don’t know the differences betweens them.

This is why I would like to know in term of performance what is the best caching method!

CFileCache seems to be simple and don’t need any php extension, but is it as performant as an APC cache for example?

No, it’s not. That’s why other backends are there.

A bytecode cache is going to give you the best performance increase. A file cache won’t give near the performance increase a dedicated one can.

APC is the most straight-forward solution, IMHO. However, you should not confuse opcode caches with cache drivers holding user content. Most opcode caches feature that too, but it’s not the same ;)

If you’re looking for a super fast solution: Try if you get lucky with memcached. It’s entirely memory-based (which also means all the cached content will be lost if the server restarts).


memcached isn’t super-fast. APC data cache is a lot faster but sometimes it’s a bit unstable.

Your decision does/should depend on the traffic you expect and the scale of your architecture. For most websites (arguably the vast majority - especially on shared hosting environments) you will have no problem using CFileCache. CFileCache does have the added benefit of being easy to work with and since it stores .bin files in the filesystem (/protected/runtime/cache/) you can add your enhancements to work with cached files, timeouts, etc.

I’ve had a pretty good experience with memcached. I only switched to using APC since I didn’t want to monitor another process in most cases.

When did the APC user cache turn unstable for you? IMHO this only happens if you haven’t assigned enough memory to APC.


Under heavy load it can segfault but this is a specific problem of particular APC, PHP and OS versions.