0

我对内存缓存有一点问题。

我的代码:

$var_key = $memcache->get($_POST['link']);
if(empty($var_key)) {
    foreach($var_key as $value) {
        $result['link_download'] = $value['link_download']; // doens't work
        $result['discription'] = $value; // it works
    }
}
else {
    foreach($html->find('.class') as $value) {
        $result['link_download'] = pq($value)->find('a:eq(1)')->attr('href');
        $result['discription'] = pq($value)->find('tr:eq(0) > td:eq(1)')->html(); 
    }
}

if(empty($var_key)) {
    $memcache->replace($_POST['link'], $result); 
    $memcache->set($_POST['link'], $result, false, 1*60);
}       

为什么$value['link_download']$value['discription']不起作用,但只是$value完美地工作?

4

1 回答 1

0

ugly, but works

$var_key = $memcache->get($_POST['link']);
$var_key = array(0=>$var_key);

if (is_array($var_key[0]) AND count($var_key[0]) > 0) {
...

... so not really recommended, just a fix to use the code you currently have without many changes!

... and the justification for this code above is given in my comments (for those of you who can't read).

于 2013-09-30T12:14:27.497 回答