2014-04-02 67 views
0

我有以下测试代码。PHP APC更新密钥和值数组

现在它是一个非常小的阵列,但实时非常大。

我该如何更新APC FOO中直接键1的值?

$test = array(
    array(
     'name' => 'Mike', 
     'lastname' => 'Last', 
    ), 
    array(
     'name' => 'test', 
     'lastname' => 'testlast', 
    ), 
    array(
     'name' => 'anothertest', 
     'lastname' => 'anothertestlast', 
    ), 
); 
apc_store('foo', $test); 
print_r(apc_fetch('foo')); 

回答

2

我不认为你可以直接在缓存中改变变量。我最好的猜测是编写一个函数,它从缓存中获取数据,对其进行修改,并将其存储回缓存中。可能是这样的:

function apc_update_array($cacheKey, $arrayKey, $array) 
{ 
    $data = apc_fetch($cacheKey); 
    $data[$arrayKey] = $array; 
    apc_store($cacheKey, $data); 
} 

使用该函数,您可以运行下面的代码来完成它。

apc_update_array(
    'foo', 
    1, 
    array(
     'name' => 'differenttest', 
     'lastname' => 'differenttestlast', 
    ) 
);