[eluser]Gamesh[/eluser]
Nice peace of code. Thanks, i added minor modifications to it.
Code:
function __call ($member, $arguments) {
$this->load->helper( array('co_cachedobjects','co_memcached') );
$this->load->library(co_loadbackend());
return co_call(&$this, $member, $arguments, $this->methodcache_expiration);
}
I think helpers and library should be loaded only when needed, not in the constructor.
And in some cases helper functions can't be found in __call method, if loaded inside __call works fine.
the call_user_method_array is deprecated should be replaced with call_user_func_array
Code:
function co_call(&$obj, $member, $arguments, $expiration)
{
$CI =& get_instance();
$class = get_class($obj);
$fn_id = array($class,$member,$arguments);
if (substr($member,-6) == 'Cached')
{
$method_name = substr($member,0,-6);
if (method_exists($obj,$method_name))
{
if ($expiration > 0)
{
if (!$CI->co_backend->get($fn_id, &$ret))
{
$ret = call_user_func_array( array(&$obj, $method_name), $arguments);
if (! $CI->co_backend->write($fn_id, $ret, $expiration) )
{
log_message('debug', "cachedobjects: cant write cache for $class->$member");
}
}
}
else
{
$ret = call_user_func_array( array(&$obj, $method_name), $arguments);
}
return $ret;
} else
{
throw new Exception("Call to undefined method ".$class."::{$method_name}()");
}
} else
{
throw new Exception("Call to undefined method ".$class."::{$method_name}()");
}
}
about the mkid function i think it should be changed to serialize instead of foreach and concating, that way any arguments could be processed.
Code:
function mkid($id) {
// Build the id. The name is an MD5 hash of the $id array
return md5(serialize($id));
}
oh and i changed cache storing a bit, cache files are now created in class_name subfolder for easy cache flushing. see method flush(class_name). somehow your class didn't have cache flushing, and i like to cache files for a very long time, but to flush the cache if anything changes. Like if you have content that doesn't change often but you need changes to take effect immediately.
Code:
$this->flush(__CLASS__);
Hope this is useful to anybody. attached the Co_backend_ci file.