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();
$toDelete = new APCIterator('user', '/^MY_APC_TESTA/', APC_ITER_VALUE);
var_dump( apc_delete($toDelete) );
showCache();
var_dump( apc_delete( array('MY_APC_TESTB_4','MY_APC_TESTB_5','MY_APC_NOT_EXISTS')) );
showCache();
var_dump( apc_delete('MY_APC_TESTB_6') );
showCache();
?>