0

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?

tereško
  • 58,060
  • 25
  • 98
  • 150
Salman Khimani
  • 515
  • 2
  • 7
  • 21

1 Answers1

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.

landons
  • 9,502
  • 3
  • 33
  • 46