note 101794 added to function.apc-delete
| From: | JFox at osu1 dot php dot net | Date: | Tue, 11 Jan 2011 17:25:36 +0000 |
| Subject: | note 101794 added to function.apc-delete | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-175646@lists.php.net to get a copy of this message | ||
Contrary to what's documented here - apc_delete also accepts and array of keys or even an
APCIterator object, making batch operations a breeze (tested in version 3.1.3p1):
<?php
function showCache() {
$cachedKeys = new APCIterator('user', '/^MY_APC/', APC_ITER_VALUE);
echo "\nkeys in cache\n-------------\n";
foreach ($cachedKeys AS $key => $value) {
echo $key . "\n";
}
echo "-------------\n";
}
apc_add('MY_APC_TESTA_1','1');
apc_add('MY_APC_TESTA_2','2');
apc_add('MY_APC_TESTA_3','3');
apc_add('MY_APC_TESTB_4','4');
apc_add('MY_APC_TESTB_5','5');
apc_add('MY_APC_TESTB_6','6');
showCache();
/* outputs:
keys in cache
-------------
MY_APC_TESTB_4
MY_APC_TESTB_5
MY_APC_TESTB_6
MY_APC_TESTA_1
MY_APC_TESTA_2
MY_APC_TESTA_3
-------------
*/
// delete all keys beginning with a regex match on MY_APC_TESTA
$toDelete = new APCIterator('user', '/^MY_APC_TESTA/', APC_ITER_VALUE);
var_dump( apc_delete($toDelete) );
// returns boolean true|false on success or failure
showCache();
/* outputs:
boolean true
keys in cache
-------------
MY_APC_TESTB_4
MY_APC_TESTB_5
MY_APC_TESTB_6
-------------
*/
// explicitly delete an array of keys
var_dump( apc_delete(
array('MY_APC_TESTB_4','MY_APC_TESTB_5','MY_APC_NOT_EXISTS')) );
// returns an array of keys that where not found/removed from the cache
showCache();
/* outputs:
array
0 => string 'MY_APC_NOT_EXISTS' (length=17)
keys in cache
-------------
MY_APC_TESTB_6
-------------
*/
// delete a single key
var_dump( apc_delete('MY_APC_TESTB_6') );
// returns boolean true|false on success or failure
showCache();
/* outputs:
boolean true
keys in cache
-------------
-------------
*/
?>
----
Server IP: 92.48.74.199
Probable Submitter: 85.224.242.81
----
Manual Page -- http://www.php.net/manual/en/function.apc-delete.php
Edit -- https://master.php.net/note/edit/101794
Del: integrated -- https://master.php.net/note/delete/101794/integrated
Del: useless -- https://master.php.net/note/delete/101794/useless
Del: bad code -- https://master.php.net/note/delete/101794/bad+code
Del: spam -- https://master.php.net/note/delete/101794/spam
Del: non-english -- https://master.php.net/note/delete/101794/non-english
Del: in docs -- https://master.php.net/note/delete/101794/in+docs
Del: other reasons-- https://master.php.net/note/delete/101794
Reject -- https://master.php.net/note/reject/101794
Search -- https://master.php.net/manage/user-notes.php