文字

apc_delete

(PECL apc >= 3.0.0)

apc_delete 从用户缓存中删除某个变量

说明

mixed apc_delete ( string $key )

从数据存储里删除某个变量。

参数

key

key 即是你用 apc_store() 存储数据时所设定的标记名称。

返回值

成功时返回 TRUE , 或者在失败时返回 FALSE

范例

Example #1 A apc_delete() 范例

<?php
$bar 
'BAR' ;
apc_store ( 'foo' $bar );
apc_delete ( 'foo' );
// this is obviously useless in this form
?>

参见

  • apc_store() - Cache a variable in the data store
  • apc_fetch() - 从缓存中取出存储的变量

用户评论:

[#1] Tom Gidden [2015-01-26 12:08:44]

To clarify "FALSE on failure", apc_delete on a key that does not exist will return FALSE; in other words, it's not just a test to see if APC works.

[#2] J Fox [2011-01-11 09:25:36]

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();



// delete all keys beginning with a regex match on MY_APC_TESTA
$toDelete = new APCIterator('user''/^MY_APC_TESTA/'APC_ITER_VALUE);

var_dumpapc_delete($toDelete) ); 
// returns boolean true|false on success or failure

showCache();



// explicitly delete an array of keys 
var_dumpapc_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();



// delete a single key
var_dumpapc_delete('MY_APC_TESTB_6') );
// returns boolean true|false on success or failure

showCache();


?>

[#3] dave1010 at gmail dot com [2010-06-03 06:26:25]

To clear out the whole APC user cache:

<?php
$info 
apc_cache_info("user");
foreach (
$info['cache_list'] as $obj) {
    
apc_delete($obj['info']);
    print 
'Deleted: ' $obj['info'] . PHP_EOL;
}
?>

上一篇: 下一篇: