Is there a performance penalty to using apc_exists() and then apc_fetch() rather than just the second function? Though I would appreciate other answers I won't be using it. Seems to me that searching the cache hash twice is a bit more costly than once. On my system there are many APC calls so I suspect it would hurt performance.
apc_exists
(PECL apc >= 3.1.4)
apc_exists — Checks if APC key exists
Return Values
Returns TRUE if the key exists, otherwise FALSE Or if an
array was passed to keys, then
an array is returned that contains all existing keys, or an empty
array if none exist.
Examples
Example #1 apc_exists() example
<?php
$fruit = 'apple';
$veggie = 'carrot';
apc_store('foo', $fruit);
apc_store('bar', $veggie);
if (apc_exists('foo')) {
echo "Foo exists: ";
echo apc_fetch('foo');
} else {
echo "Foo does not exist";
}
echo PHP_EOL;
if (apc_exists('baz')) {
echo "Baz exists.";
} else {
echo "Baz does not exist";
}
echo PHP_EOL;
$ret = apc_exists(array('foo', 'donotexist', 'bar'));
var_dump($ret);
?>
The above example will output something similar to:
Foo exists: apple
Baz does not exist
array(2) {
["foo"]=>
bool(true)
["bar"]=>
bool(true)
}
See Also
- apc_cache_info() - Retrieves cached information from APC's data store
- apc_fetch() - Fetch a stored variable from the cache
tcawe at colnect punto com
16-Oct-2010 08:20
