[eluser]Phil Sturgeon[/eluser]
Added a new function to my verion of this library.
Code:
function call($property, $method, $arguments = array(), $expires = null)
{
// Clean given arguments to a 0-index array
$arguments = array_values($arguments);
$cache_file = $property.'/' . $method . '-'.md5(serialize($arguments));
// See if we have this cached
$cached_responce = $this->get($cache_file);
// Not FALSE? Return it
if($cached_responce)
{
return $cached_responce;
}
else
{
// Call the model or library with the method provided and the same arguments
$new_responce = call_user_func_array(array($this->ci->$property, $method), $arguments);
$this->write($new_responce, $cache_file, $expires);
return $new_responce;
}
}
I spent ages trying to think of a brilliant OOP overloaded way of caching model/library without modifiying it. Tried extending the Models class and all sorts of crazyness, but in the end I ended up with this syntax.
Code:
$this->data->page = $this->cache->call('pages_m', 'getBySlug', array($slug, DEFAULT_LANGUAGE), $this->settings->item('page_cache'))
The parameters are model name, method name and then an array of params for that method. Also added a 4th param for cache expirey to act in the same way as your other functions.
Use it if you like, up to you. :-)