Cdbcache Help

Can someone help me with CDbCache. Every time I load a page (only once data has been inputted in the cache table) I get the following error: [b]unserialize() [<a href=‘function.unserialize’>function.unserialize</a>]: Error at offset 0 of 1281 bytes


The only info I found was here.

Weird thing is that I am not sure why every page is being cached. I verified that my cache table is getting data but I only specify to add to cache in my code below in one action.

This is my main.php settings:

    'cache' => array(

      'class' => 'CDbCache',




This is my code for the only action I am calling $cache:

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

    $factsAtAGlance = $cache['brand_reports_pw_facts_at_a_glance'];


    if($factsAtAGlance === FALSE || $factsAtAGlance === NULL) {

      $factsAtAGlance = $reports->getFactsAtAGlance($brand);

      $cache['brand_reports_pw_facts_at_a_glance'] = $factsAtAGlance;


Stack Trace


+  /Applications/MAMP/htdocs/leadworks/framework/caching/CCache.php(108): unserialize("x613a323a7b693a303b613a323a7b693a303b613a313a7b693a303b4f3a383a2...")


+  /Applications/MAMP/htdocs/leadworks/framework/web/CUrlManager.php(219): CCache->get("Yii.CUrlManager.rules")


+  /Applications/MAMP/htdocs/leadworks/framework/web/CUrlManager.php(206): CUrlManager->processRules()


+  /Applications/MAMP/htdocs/leadworks/framework/base/CModule.php(387): CUrlManager->init()


+  /Applications/MAMP/htdocs/leadworks/framework/base/CApplication.php(510): CModule->getComponent("urlManager")


+  /Applications/MAMP/htdocs/leadworks/framework/web/CWebApplication.php(140): CApplication->getUrlManager()


+  /Applications/MAMP/htdocs/leadworks/framework/base/CApplication.php(169): CWebApplication->processRequest()


+  /Applications/MAMP/htdocs/leadworks/leadworks/index.php(15): CApplication->run()

What database are you using? Could you show us the schema of your cache table?

I am using POSTGRESQL. It automatically created the table ‘yiicache’.

TABLE yiicache

  id character(128) NOT NULL,

  expire integer,

  value bytea,

  CONSTRAINT yiicache_pkey PRIMARY KEY (id)

This can be caused by charset mismatch. Check db connection properties.

Can’t see anything bad here but perhaps I am missing something here?:

	'connectionString' => 'pgsql:host=localhost;port=5432;dbname=*******',

	'emulatePrepare' => true,

	'username' => 'postgres',

	'password' => '******',

	'charset' => 'utf8',


  'enableParamLogging' => true,

Seems ok.

Have you tried cleaning the cache? maybe some records are corrupted.

Yes I manually deleted the rows from the database. The page loads the first time but once there is a cache row it gives the serialization error.

I think I saw some issues on Github about using ‘bytea’ type in PostgreSQL. That surely is a reason for passing invalid data to unserialize(). Maybe try searching on Github for it as someone could post a solution in one of comments.