Welcome Guest, Not a member yet? Register   Sign In
How to use integrated Cache class in router.php?

In one of my project I need to create a Dynamic Routing. It means that I need to change the routing regular regarding the different domain. And I store the routing regular of each domain in Memcache, which can be accessed through port 11211.
Indeed now I can use origin PHP memcache class in router.php, but it seems too stupid. Maybe in the future I need to change to another cache system, like Redis or even MySQL. So how can I use the integrated Cache class in router.php?

Another question, as my former thread has mentioned, I'm using cache as autoload driver, how to designate a specific cache driver in autoload?

PHP Code:
$autoload['drivers'] = array('cache'); 

The router is loaded before the get_instance() function is defined, so you wouldn't be able to load the memcached driver for the cache library, even if you could load the library itself. You could build your own class to abstract the cache methods needed for your routing, though.

As for autoloading the Cache library with the correct drivers, create a file: /application/config/cache.php with the following:
PHP Code:
$config['adapter'] = 'memcached';
$config['backup'] = 'dummy'// or whatever backup driver you want
$config['key_prefix'] = ''// or whatever key_prefix you want 

Then make sure the settings in /application/config/memcached.php are correct.

Theme © iAndrew 2016 - Forum software by © MyBB