Caching Not Working With Cmemcache

Hi there,

I want to use memcached for caching the DB schema as well as some SQL queries.

I have installed memcached on my machine.

In my main.php config file I have

        'cache' => array(

            'class' => 'system.caching.CMemCache',

            'servers' => array(

                array('host' => 'localhost', 'port' => 11211),            



I wrote a test action that works perfectly as expected, using both Memcache class and Yii’s cache component:

    public function actionTestMemCache() {

        echo 'Using PHP Memcache <br>';

        $memcache = new Memcache;

        $memcache->connect('localhost', 11211) or die("Could not connect");

        $version = $memcache->getVersion();

        echo "Server's version: " . $version . "<br/>\n";

        $tmp_object = new stdClass;

        $tmp_object->str_attr = 'test';

        $tmp_object->int_attr = 123;

        $memcache->set('key', $tmp_object, false, 10) or die("Failed to save data at the server");

        echo "Store data in the cache (data will expire in 10 seconds)<br/>\n";

        $get_result = $memcache->get('key');

        echo "Data from the cache:<br/>\n";



        $c = Yii::app()->cache;


        $class = get_class($c);


        echo "<br><br>Using Yii $class <br>";


        $c->set('x', 1);

        $c->set('y', 2);

        $c->set('z', 3);

        $data = $c->mget(array('x', 'z'));

        echo $data['z']; // 3


Now in my db component config I have:

'db' => array('connectionString' => "mysql:host=localhost;dbname=xxx",

            'emulatePrepare' => true,

            'schemaCachingDuration' => 604800, //one week

            'enableParamLogging' => true,

            'username' => 'admin',

            'password' => 'pass',

            'charset' => 'utf8',

            'class' => 'CDbConnection',

            'enableProfiling' => true,

            'initSQLs'=>array("set time_zone='Europe/London';"),  


Now whenever I execute some AR stuff I still see the SHOW FULL COLUMNS query in the profiling. And one of my query that uses Yii::app()->db->cache(606024)->createCommand() is always called too.

So I really don’t understand what’s going on with memcached. The funny thing is if I use CFileCache, everything works as expected and I do see performance improvement !

In conclusion my Memcache test function works, all my config is fine (as it works with CFileCache) but Memcache + db caching does not work at all…

Any idea?