diff --git a/reference/apcu/functions/apcu-fetch.xml b/reference/apcu/functions/apcu-fetch.xml index d394f819c..efee26a6b 100644 --- a/reference/apcu/functions/apcu-fetch.xml +++ b/reference/apcu/functions/apcu-fetch.xml @@ -4,14 +4,14 @@ apcu_fetch - Fetch a stored variable from the cache + Fetch a stored value from the cache &reftitle.description; mixedapcu_fetch - mixedkey + stringarraykey boolsuccess @@ -26,8 +26,10 @@ The key used to store the value (with - apcu_store). If an array is passed then each - element is fetched and returned. + apcu_store). If an array of keys is passed then + each key is fetched, and the entries which are found in the cache are + returned as an array. Array elements that are not strings are skipped + and an E_WARNING is raised. @@ -35,7 +37,9 @@ success - Set to &true; in success and &false; in failure. + Set to &true; on success and &false; on failure. If + key is an array, it is always set to &true;, + even if none of the keys exist in the cache. @@ -44,8 +48,21 @@ &reftitle.returnvalues; - The stored variable or array of variables on success; &false; on failure + If key is a string, returns the stored value, or + &false; if the key does not exist in the cache or has expired. + + If key is an array, returns an associative array + which maps each key found in the cache to its stored value. Keys that do + not exist in the cache are omitted from the returned array. + + + + As &false; can also be stored as a value, use the + success parameter to distinguish a stored &false; + from a failure. + + @@ -87,6 +104,37 @@ var_dump(apcu_fetch('foo')); + + + + Fetching multiple entries with <function>apcu_fetch</function> + + 13, 'rate' => 22]); + +$values = apcu_fetch(['progress', 'rate', 'missing'], $success); +var_dump($values, $success); + +// The returned array can be destructured into variables +['progress' => $progress, 'rate' => $rate] = $values; +var_dump($progress, $rate); +?> +]]> + + &example.outputs; + + + int(13) + ["rate"]=> + int(22) +} +bool(true) +int(13) +int(22) ]]>