Kontrollbase gets Memcache support

After working with Memcache on another application I figured that Kontrollbase could benefit from it as well. Expect in the next release (coming this week), easily configurable support for memcache. This makes use of the memcache library for CodeIgniter talked about here: http://codeigniter.com/forums/viewthread/72538/

In the config.php file you just enable it and set the proper connection parameters.

$config['memcache_enabled'] = TRUE;
$config['memcache_ip'] = '127.0.0.1';
$config['memcache_port'] = '11211';

In the main controller I added the following code to the index and host functions.

$this->load->library('cache');
// memcache library information
$memcache = $this->config->item('memcache_enabled');
if($memcache == TRUE) {
$memcache_ip = $this->config->item('memcache_ip');
$memcache_port = $this->config->item('memcache_port');
$memcache = $this->cache->useMemcache($memcache_ip, $memcache_port);
if(!$memcache) {
log_message('debug', "Memcache connection failure.");
show_error("Memcache library not enabled correctly.");
}
else {
log_message('debug', "Memcache enabled!");
}
}
else {
log_message('debug', "Memcache not enabled in config.");
}
//end memcache

And then to load the view into the cache we see this later on…

$this->cache->save('cachedMain',$this->load->view('main/main', $g, TRUE),NULL,3600);

Read More