CakeFest 2024: The Official CakePHP Conference

apcu_exists

(PECL apcu >= 4.0.0)

apcu_existsエントリが存在するかどうかを調べる

説明

apcu_exists(mixed $keys): mixed

指定した APCu エントリが存在するかどうかを調べます。

パラメータ

keys

キーを含む文字列、あるいは文字列の配列。

戻り値

キーが存在する場合に true、それ以外の場合に false を返します。 keys に配列を渡したときは、 存在するキーをすべて含む配列を返します。 どれも存在しない場合は空の配列を返します。

例1 apcu_exists() の例

<?php
$fruit
= 'apple';
$veggie = 'carrot';

apcu_store('foo', $fruit);
apcu_store('bar', $veggie);

if (
apcu_exists('foo')) {
echo
"Foo exists: ";
echo
apcu_fetch('foo');
} else {
echo
"Foo does not exist";
}

echo
PHP_EOL;
if (
apcu_exists('baz')) {
echo
"Baz exists.";
} else {
echo
"Baz does not exist";
}

echo
PHP_EOL;

$ret = apcu_exists(array('foo', 'donotexist', 'bar'));
var_dump($ret);

?>

上の例の出力は、 たとえば以下のようになります。

Foo exists: apple
Baz does not exist
array(2) {
  ["foo"]=>
  bool(true)
  ["bar"]=>
  bool(true)
}

参考

  • apcu_cache_info() - APCu のデータから、キャッシュされた情報を取得する
  • apcu_fetch() - 格納されている変数をキャッシュから取得する
add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top