Yii Framework Forum: Switching between caches - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Switching between caches Rate Topic: -----

#1 User is offline   andser 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 31
  • Joined: 12-February 10

Posted 12 February 2010 - 10:19 AM

Hi, pepople!

Howto implement\configure switching between multiple caches. For example, to cache data - use CMemCache and for pages and their fragments - CFileCache.

Thanks.
0

#2 User is offline   Y!! 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 978
  • Joined: 18-June 09

Posted 12 February 2010 - 11:14 AM

Hi, first of all you should define all possible Cache components in config. Example:cache (uses CFileCache) and remoteCache (uses CMemCache).

Now for fragments-caching. Let's assume you want to cache fragments remotely:

if ($this->beginCache($key, array('cacheID' => 'remoteCache')))
{

   // Generate data...

   $this->endCache();

}


By default, 'cacheID' is set to 'cache'. So if you want to store in file you can just do:

if ($this->beginCache($key))
// ...


Other components like CCacheHttpSession have also $cacheID attribute. So if you want to store sessions remotely you can do:

'components' => array(
   ...
   'session' => array(
      'class' => 'CCacheHttpSession',
      'cacheID' => 'remoteCache',
   ),
   ...
),

0

#3 User is offline   andser 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 31
  • Joined: 12-February 10

Posted 12 February 2010 - 12:03 PM

View PostY!!, on 12 February 2010 - 11:14 AM, said:

Hi, first of all you should define all possible Cache components in config. Example:cache (uses CFileCache) and remoteCache (uses CMemCache).

Now for fragments-caching. Let's assume you want to cache fragments remotely:

if ($this->beginCache($key, array('cacheID' => 'remoteCache')))
{

   // Generate data...

   $this->endCache();

}


By default, 'cacheID' is set to 'cache'. So if you want to store in file you can just do:

if ($this->beginCache($key))
// ...


Other components like CCacheHttpSession have also $cacheID attribute. So if you want to store sessions remotely you can do:

'components' => array(
   ...
   'session' => array(
      'class' => 'CCacheHttpSession',
      'cacheID' => 'remoteCache',
   ),
   ...
),



Ohhh! I missed 'cacheID' param in api book. Thank you! It's working!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users