Welcome Guest, Not a member yet? Register   Sign In
MP_Cache: Simple flexible Partial Caching
#17

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


Messages In This Thread
MP_Cache: Simple flexible Partial Caching - by El Forum - 01-17-2009, 04:28 PM
MP_Cache: Simple flexible Partial Caching - by El Forum - 01-17-2009, 09:36 PM
MP_Cache: Simple flexible Partial Caching - by El Forum - 01-19-2009, 08:34 AM
MP_Cache: Simple flexible Partial Caching - by El Forum - 01-19-2009, 10:30 AM
MP_Cache: Simple flexible Partial Caching - by El Forum - 04-06-2009, 09:01 AM
MP_Cache: Simple flexible Partial Caching - by El Forum - 04-19-2009, 04:43 AM
MP_Cache: Simple flexible Partial Caching - by El Forum - 04-19-2009, 05:41 AM
MP_Cache: Simple flexible Partial Caching - by El Forum - 04-19-2009, 03:34 PM
MP_Cache: Simple flexible Partial Caching - by El Forum - 04-19-2009, 04:42 PM
MP_Cache: Simple flexible Partial Caching - by El Forum - 04-19-2009, 05:40 PM
MP_Cache: Simple flexible Partial Caching - by El Forum - 04-19-2009, 05:41 PM
MP_Cache: Simple flexible Partial Caching - by El Forum - 04-20-2009, 10:31 AM
MP_Cache: Simple flexible Partial Caching - by El Forum - 04-20-2009, 12:01 PM
MP_Cache: Simple flexible Partial Caching - by El Forum - 04-20-2009, 04:16 PM
MP_Cache: Simple flexible Partial Caching - by El Forum - 04-20-2009, 04:37 PM
MP_Cache: Simple flexible Partial Caching - by El Forum - 04-20-2009, 04:42 PM
MP_Cache: Simple flexible Partial Caching - by El Forum - 04-21-2009, 04:42 PM
MP_Cache: Simple flexible Partial Caching - by El Forum - 08-06-2009, 08:37 AM
MP_Cache: Simple flexible Partial Caching - by El Forum - 08-12-2009, 02:14 AM
MP_Cache: Simple flexible Partial Caching - by El Forum - 08-12-2009, 05:32 AM
MP_Cache: Simple flexible Partial Caching - by El Forum - 08-12-2009, 05:35 AM
MP_Cache: Simple flexible Partial Caching - by El Forum - 08-12-2009, 08:31 AM
MP_Cache: Simple flexible Partial Caching - by El Forum - 08-12-2009, 08:43 AM
MP_Cache: Simple flexible Partial Caching - by El Forum - 09-18-2009, 06:42 AM
MP_Cache: Simple flexible Partial Caching - by El Forum - 09-23-2009, 04:50 AM
MP_Cache: Simple flexible Partial Caching - by El Forum - 12-04-2009, 02:15 PM
MP_Cache: Simple flexible Partial Caching - by El Forum - 12-20-2009, 07:22 PM
MP_Cache: Simple flexible Partial Caching - by El Forum - 01-28-2010, 06:16 AM
MP_Cache: Simple flexible Partial Caching - by El Forum - 01-28-2010, 06:24 AM
MP_Cache: Simple flexible Partial Caching - by El Forum - 01-28-2010, 07:21 AM
MP_Cache: Simple flexible Partial Caching - by El Forum - 02-25-2010, 02:10 PM
MP_Cache: Simple flexible Partial Caching - by El Forum - 02-25-2010, 04:13 PM
MP_Cache: Simple flexible Partial Caching - by El Forum - 02-25-2010, 05:32 PM
MP_Cache: Simple flexible Partial Caching - by El Forum - 02-25-2010, 06:22 PM
MP_Cache: Simple flexible Partial Caching - by El Forum - 02-26-2010, 06:39 AM
MP_Cache: Simple flexible Partial Caching - by El Forum - 04-11-2010, 03:03 AM
MP_Cache: Simple flexible Partial Caching - by El Forum - 04-11-2010, 03:20 AM
MP_Cache: Simple flexible Partial Caching - by El Forum - 04-11-2010, 10:30 AM
MP_Cache: Simple flexible Partial Caching - by El Forum - 04-16-2010, 07:52 AM



Theme © iAndrew 2016 - Forum software by © MyBB