[eluser]XMadMax[/eluser]
hey Bayss, better to be in a single library file, but if you have ever the same similar functions, would be better to make a Cache_Controller. All your controllers that need cache, can extend from this.
I have a magic method, where any method inside a controller that does not exists, and exists a method as '_{method_name}', means that this method can be cached.
Example:
Calll: /test/method01
If found '_method01' inside test.php, then means that this method can be cached.
Cache_Controller can take care of this with: if(method_exists($this, '_'.$methodName))
Example:
Code:
class Test extends Cache_Controller {
.....
function _mehtod1($params) {
....
}
Code:
class Cache_Controller extends CI_Controller
{
function __call($methodName, $arguments) {
$cachemethod = false;
if(method_exists($this, '_'.$methodName)) {
$cachemethod = true;
// check cache, if available, get cache in $result, else:
$result = call_user_func_array(array(&$this, '_'.$methodName), $arguments);
}
else
$result = call_user_func_array(array(&$this, $methodName), $arguments);
if ($cachemethod )
// Write cache
return $result;
}
}
Hope it helps.