问题
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?
回答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.
来源:https://stackoverflow.com/questions/10000491/how-to-turn-off-on-memcache-in-code-igniter