[eluser]Braden Schaeffer[/eluser]
@ralf57
Um.... didn't know about that library.
It looks like mine is a little bit simpler. Phil's library has apparently implemented data retrieval methods within the class, while mine is more straight forward:
Here's an example:
Code:
<?php
class Cache_example extends Controller {
function Cache_example()
{
parent::Controller();
$this->load->library("cache");
}
// Simple Example
function example()
{
// Did the cache library return FALSE, meaning there was no cache file
if(($data = $this->cache->get("my_folder", "my_custom_cache_name") === FALSE)
{
// Use your own methods to return some data
$this->load->model("my_model");
$data = $this->my_model->get_some_data();
// Attempt to write a new cache file for next time
$this->cache->write("my_folder", "my_custom_cache_name", $data);
// You can optionally send a custom expiration in minutes (in lieu of the
// default set in your config file) as the 4th parameter... like so:
//
// $this->cache->write("my_folder", "my_custom_cache_name", $data, 30);
}
$this->load->view("some_view", $data);
}
// Semi-Advanced Example
function posts($post_id)
{
if(($data = $this->cache->get("blog_posts", $post_id) === FALSE)
{
// Exaggerated Data Retrieval
$this->load->model(array("blog_model", "pictures_model"));
$data['posts'] = $this->blog_model->get_posts();
$data['recent_comments'] = $this->blog_model->get_recent_comments();
$data['pictures'] = $this->pictures_model->get_pictures();
$this->cache->write("blog_posts", $post_id, $data);
}
$this->load->view("blog_posts", $data);
}
}
I guess you can imagine caching any function that returns data in a fairly simple way. Cache whatever you want... you know? Also.. I haven't added a
delete method yet.
His library looks pretty nifty though... might have to take a look at it.