= 4.0.0)apcu_store — 緩存一個(gè)變量到存儲(chǔ)中 說明apcu_store(string $key, mixed $var, int $ttl = 0): boolapcu_store(array $values, mixed $unused">

apcu_store

(PECL apcu >= 4.0.0)

apcu_store 緩存一個(gè)變量到存儲(chǔ)中

說明

apcu_store(string $key, mixed $var, int $ttl = 0): bool
apcu_store(array $values, mixed $unused = NULL, int $ttl = 0): array

緩存一個(gè)變量到存儲(chǔ)中。

注意: 與 PHP 中常見的變量生命周期不同的是,通過 apcu_store() 存儲(chǔ)的變量可以在多個(gè) request 之間共享(直到該變量從 cache 中被刪除)。

參數(shù)

key

使用此名稱存儲(chǔ)變量。key 是唯一的,因此當(dāng)多次使用同樣的 key 存儲(chǔ)變量時(shí),后一次會(huì)覆蓋前一次的值。

var

被存儲(chǔ)的變量

ttl

變量生存時(shí)間(Time To Live);被存儲(chǔ)的 var 經(jīng)過 ttl 秒后,會(huì)從存儲(chǔ)中被刪除(下一次請求時(shí))。如果沒提供 ttl (或 ttl0 ),該變量會(huì)一直存在直到手動(dòng)刪除它,或者其他原因?qū)е略撟兞繌木彺嬷邢Вㄇ宄?,重啟等等。)?

values

數(shù)組索引作為 key,數(shù)組值作為被存儲(chǔ)的 var。

返回值

成功時(shí)返回 true, 或者在失敗時(shí)返回 false。 第二種語法返回包含存儲(chǔ)失敗的 key 的數(shù)組。

范例

示例 #1 apcu_store() 示例

<?php
$bar 
'BAR';
apcu_store('foo'$bar);
var_dump(apcu_fetch('foo'));
?>

以上例程會(huì)輸出:

string(3) "BAR"

參見