Member Avatar for iamthwee

I'm just wondering what the codeigniter caching library does and where it might be useful, or what problems people have encountered with it are.

Recommended Answers

All 6 Replies

it is similar to the template engine cache function. The only difference is that in template engine such as smarty, we can define which block of contents should be ignore by the cacheing mechanism.

In codeigniter, it will keep the cached the contents based on the definition of $x as time in minutes.

$this->output->cache($x); // $x is the number of minutes

Warning!
Only use this function outside the form, login form, user's account page, administration page and other contents where login authentication is required.

If you will be using this function, it is helpful to create a purging script or class to give you the option to purge the cached content on demand without manually deleting them.

It is useful in delivering contents that don't change a lot. For example, a front page with content from the database that don't change a lot can use the cache function. It will definitely saves a great deal of server resources by just loading the cache page rather than executing a database fetch queries for the contents.

Here are some pages that may help contribute to answering your question (I am new to this question, so i apologize for any mistakes):
http://ellislab.com/codeigniter/user-guide/database/caching.html
http://ellislab.com/codeigniter/user-guide/libraries/caching.html
http://ellislab.com/codeigniter/user-guide/general/caching.html
http://stackoverflow.com/questions/18192259/codeigniter-cache-view-into-a-view

I hope they help! I too hope to learn something new from this question.

Firstly, it caches the entire fully-rendered page, which means that it isn't a good solution for logged in pages that are user-specific, because you can't use it to cache just a portion of a page.

Secondly, the file cache gets stored in the file system, so make sure you aren't caching hundreds of thousands of pages, because that can significantly slow things down instead of speed them up. And I believe there's a max limit to how many pages can be stored in a single directory depending on the file system, as well.

Thirdly, a limitation of CI's built in file caching system is that it is hardcoded to only spit out HTML files. I actually had to modify it myself to allow the caching of other mime types, so that I could use it for our RSS feeds, for example (which, IMO, is a very good use of file caching!)

commented: oh i see +10
Member Avatar for iamthwee

Sounds like if the page or queries need to be updated you could cause an issue with caching so I think I'm going to avoid this as I don't really know which db queries remain constant or pages remain unchanged for the time being.

Thanks for the insight.

Well that's the trade-off with any caching mechanism ... faster in exchange for potentially stale content.

We use Memcached very heavily to cache database queries and things of that sort. We use an adapted version of CodeIgniter's caching mechanism, which is capable of handling any mime type, to cache our RSS feeds, API calls that don't use an OAuth token, and our tag clouds (which rarely change). We can cache our tag clouds, even though they're just a portion of the page, because they're injected via an IFRAME ... err, actually, using jQuery.load(), but same difference.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.