How to turn off/on memcache in Code Igniter

早过忘川 提交于 2019-12-11 20:06:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!