How to turn off/on memcache in Code Igniter

2019-09-08 11:46发布

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条回答
smile是对你的礼貌
2楼-- · 2019-09-08 12:25

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.

查看更多
登录 后发表回答