如何在代码Igniter中关闭/打开内存缓存 [英] How to turn off/on memcache in Code Igniter

查看:144
本文介绍了如何在代码Igniter中关闭/打开内存缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过一个常量来处理内存缓存功能,如:define('CACHE_ON',1)或define('CACHE_ON',0)。
我们在获取/保存记录时在模型中使用load-> driver函数。是否有任何功能可以打开/关闭缓存功能?

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?

推荐答案

您可以定义自己的常量,然后加载memcache在 CACHE_ON 为0时:

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;
}

如果您引用了 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.

这篇关于如何在代码Igniter中关闭/打开内存缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆