If you want to save on model queries you can do this, in a controller for example:
// try cache
$cache_id = 'mycache';
if(!$data = $this->fuel->cache->get($cache_id)) {
$this->load->model('data_model');
$data = $this->data_model->find_all_array(NULL, 'last_modified DESC');
$this->fuel->cache->save($cache_id, $data, NULL, 3600);
}
// ....use the $data as intended
So all that happens here is a test to see if the cached item is valid, if not, run the query and create a new cache item. Note that $data is is populated in either case. The $cache_id will be MD5'd in the application/cache directory, but if you identify the file by timestamp for example, you'll see that the data is serialized, like most other cache libraries.
No comments:
Post a Comment