Sharing Cache Keys Between Console And Web App

Hi,

I am creating a CFileCache using the console app. But I’m unable share that cache with the web app. Any idea how to share caches created from console to the web app?

In my console app:




$cacheId = "testCache";

Yii::app()->cache->set($cacheId, $fileContent);



In my web app:




$cacheId = "testCache";

Yii::app()->cache->get($cacheId)



In both config/main.php and config/console.php I have included the caching component:




'components'=>array(

    'cache'=>array(

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

      ),

),



But the sharing between the console app and the web app doesn’t work.

You should explicitly configure "keyPrefix" property of the cache components both in web and in console … they have to share the same prefix if they should share the same cache data.

http://www.yiiframework.com/doc/api/1.1/CCache#keyPrefix-detail




'components'=>array(

    'cache'=>array(

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

         'keyPrefix' => 'my_cache',

      ),

),