Update:
According to the accepted answer below, I tested a negative number:
$negativeInt = -1;
Cache::write('my-test-count', $negativeInt, 'short');
$readVal = Cache::read('my-test-count', 'short');
debug($readVal);
exit;
The unseralize error is reproduced sequentially when trying to read any negative number. This is now an accepted error, which, I believe, will be resolved at 2.8.1
The original question:
I keep getting this error, but I can’t understand why and even how to continue troubleshooting.
The line that throws an error should only go if it Cache::read()returns false. But this line would throw a non-serialization error if I didn't put @ in front of it.
:
Redis Noterialize? "", , , ::read. , (int) (. ), , , .
(8): unserialize(): 0 2 [APP/Vendor/pear-pear.cakephp.org/CakePHP/Cake/Cache//RedisEngine.php, 136]
:
> unserialize - [internal], line ??
> RedisEngine::read() - APP/Vendor/pear-pear.cakephp.org/CakePHP/Cake/Cache/Engine/RedisEngine.php, line 136
> Cache::read() - APP/Vendor/pear-pear.cakephp.org/CakePHP/Cake/Cache/Cache.php, line 358
> Cache::remember() - APP/Vendor/pear-pear.cakephp.org/CakePHP/Cake/Cache/Cache.php, line 567
> Item::getCount() - APP/Model/Item.php, line 812
, :
public function getCount($id) {
$model = $this;
return Cache::remember('item' . $id. '_count', function() use ($model, $id) {
$count = $model->find('count', array(
'conditions' => array(
$model->alias . '.status' => 1,
$model->alias . '.id' => $id
)
));
return ($count === false) ? 0 : (int)$count;
}, 'my_counts');
}
public function decrementCount($id, $offset = 1) {
if(empty($id)) return false;
$count = @Cache::read('item' . $id . '_count', 'my_counts');
if($count === false) {
$this->getCount($id);
} else {
Cache::decrement('item' . $id . '_count', $offset, 'my_counts');
}
}
public function incrementCount($id, $offset = 1) {
if(empty($id)) return false;
$count = @Cache::read('item' . $id. '_count', 'my_counts');
if($count === false) {
$this->getCount($id);
} else {
Cache::increment('item' . $id. '_count', $offset, 'my_counts');
}
}
UPDATE:
( 1-20 ). Cache::remember(...:
$toReturn = Cache::read('item' . $id. '_count', 'my_counts');
debug($toReturn);
:
- debug: (int) 0
- debug: (int) 0
- (8): unserialize(): ... ( : )
- debug: false
- (8): unserialize(): ... ( Cache::
- debug: (int) 0
- (8): unserialize(): ... ( : )
- debug: false
- (8): unserialize(): ... ( Cache::
- 0
- 3
- 1
- 1
...