Yii Framework Forum: CCache/CMemCache issues - Yii Framework Forum

Jump to content

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

CCache/CMemCache issues Rate Topic: -----

#1 User is offline   terryxiang 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 13-April 10

Posted 14 April 2010 - 08:14 AM

Hi

It seems trying to cache an empty array will cause unserialize failed when retrieving.

memcached-tool dump showed results:
a:2:{i:0;a:0:{}i:1;N;}


trying Yii::app()->cache-get($key)
Yii unserialize() expects parameter 1 to be string, array given


See CCache.php Line 84, I modified

$data=unserialize($value);


To

if(!is_string($value))
{
    $data = $value;
}
else
{
    $data=unserialize($value);
}


Or add

                if($value === false || ( is_array($value) && empty($value) ) )
                        return;

on line 144 to avoid set an empty array value.

I don't know if it is the right way, just works.

Another question, I write a class named CacheManager, just a proxy call for Yii::app()->cache, like this
public function set($key, $value)
{
    Yii::app()->cache->set($key, $value);
}


But I can find unserialized data in cache by this function call, calling Yii::app()->cache->set directly always store serialized data in cache, I don't understand why, I had to add checks above to CCache.

any suggestions will be appreciated.
0

#2 User is offline   vamp 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 181
  • Joined: 30-January 09

Posted 14 April 2010 - 09:02 AM

each realization of CCache in getValue() function can't return array (if you didn't set it without using of CCache)
-Posted Image-
Thanks, you make me stronger!
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