How to turn off/on memcache in Code Igniter

Go To StackoverFlow.com

0

I want to handle memcache functionality globally via one constant like : define('CACHE_ON',1) or define ('CACHE_ON',0). we use load->driver function in models when fetching/saving records. Is there any function that switches on/off cache functionality?

2012-04-03 20:02
by Salman Khimani


1

You could define your own constant, and then load either the memcache driver, or dummy in the event that CACHE_ON is 0:

<?php
// Wherever you load your "cache" driver...
$this->load->driver('cache');
if (defined('CACHE_ON') && !CACHE_ON)
{
    $this->cache_driver =& $this->cache->dummy;
}
else
{
    $this->cache_driver =& $this->cache->memcache;
}

If you've referenced the memcache driver directly, you'll have to refactor some code. There's no a global on/off switch, but you can create your own by refactoring.

2012-04-04 07:40
by landons