简体   繁体   English

如何在 Code Igniter 中关闭/打开内存缓存

[英]How to turn off/on memcache in Code Igniter

I want to handle memcache functionality globally via one constant like: define('CACHE_ON',1) or define ('CACHE_ON',0).我想通过一个常量全局处理内存缓存功能,例如:define('CACHE_ON',1) 或 define ('CACHE_ON',0)。 we use load->driver function in models when fetching/saving records.我们在获取/保存记录时在模型中使用 load->driver function。 Is there any function that switches on/off cache functionality?是否有任何 function 可以打开/关闭缓存功能?

You could define your own constant, and then load either the memcache driver, or dummy in the event that CACHE_ON is 0:您可以定义自己的常量,然后在CACHE_ON为 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.如果您直接引用了memcache驱动程序,则必须重构一些代码。 There's no a global on/off switch, but you can create your own by refactoring.没有全局开/关开关,但您可以通过重构创建自己的开关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM