Welcome Guest, Not a member yet? Register   Sign In
CachedObjects v1.2 - cache granularity as you want
#17

[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.


Messages In This Thread
CachedObjects v1.2 - cache granularity as you want - by El Forum - 06-02-2008, 08:16 PM
CachedObjects v1.2 - cache granularity as you want - by El Forum - 06-04-2008, 04:29 PM
CachedObjects v1.2 - cache granularity as you want - by El Forum - 06-04-2008, 04:51 PM
CachedObjects v1.2 - cache granularity as you want - by El Forum - 06-04-2008, 05:07 PM
CachedObjects v1.2 - cache granularity as you want - by El Forum - 06-04-2008, 05:28 PM
CachedObjects v1.2 - cache granularity as you want - by El Forum - 06-05-2008, 02:26 AM
CachedObjects v1.2 - cache granularity as you want - by El Forum - 06-17-2008, 03:32 PM
CachedObjects v1.2 - cache granularity as you want - by El Forum - 06-18-2008, 09:28 AM
CachedObjects v1.2 - cache granularity as you want - by El Forum - 06-19-2008, 07:09 AM
CachedObjects v1.2 - cache granularity as you want - by El Forum - 06-21-2008, 02:06 AM
CachedObjects v1.2 - cache granularity as you want - by El Forum - 06-21-2008, 05:38 AM
CachedObjects v1.2 - cache granularity as you want - by El Forum - 06-21-2008, 01:50 PM
CachedObjects v1.2 - cache granularity as you want - by El Forum - 06-21-2008, 11:00 PM
CachedObjects v1.2 - cache granularity as you want - by El Forum - 06-22-2008, 04:55 AM
CachedObjects v1.2 - cache granularity as you want - by El Forum - 06-22-2008, 09:20 PM
CachedObjects v1.2 - cache granularity as you want - by El Forum - 09-28-2009, 08:24 AM
CachedObjects v1.2 - cache granularity as you want - by El Forum - 06-07-2010, 05:27 AM



Theme © iAndrew 2016 - Forum software by © MyBB