Using CodeIgniter caching

You can use CodeIgniter caching to cache (or temporarily store) practically anything. As an example of caching with CodeIgniter, we're going to cache an RSS feed. We could, of course, cache anything we wanted; however, caching an RSS feed is a good place to start. Working with RSS is quite simple and the recipe can easily be converted to cache feeds from other sources, such as a call to Twitter, for example.

How to do it...

We're going to create the /path/to/codeigniter/application/controllers/rss_cache.php file.

  1. Create the preceding file and add the following code to it:
    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Rss_cache extends CI_Controller { function __construct() { parent::__construct(); ...

Get CodeIgniter 2 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.