PHP Doku:: Removes a stored variable from the cache - function.apc-delete.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzDas Verhalten von PHP beeinflussenAlternativer PHP CacheAPC Funktionenapc_delete

Ein Service von Reinhard Neidl - Webprogrammierung.

APC Funktionen

<<apc_delete_file

apc_exists>>

apc_delete

(PECL apc >= 3.0.0)

apc_delete Removes a stored variable from the cache

Beschreibung

bool apc_delete ( string $key )

Removes a stored variable from the cache.

Parameter-Liste

key

The key used to store the value (with apc_store()).

Rückgabewerte

Gibt bei Erfolg TRUE zurück. Im Fehlerfall wird FALSE zurückgegeben.

Beispiele

Beispiel #1 A apc_delete() example

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

Siehe auch


2 BenutzerBeiträge:
- Beiträge aktualisieren...
J Fox
11.01.2011 18:25
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
-------------
-------------
*/
?>
dave1010 at gmail dot com
3.06.2010 15:26
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;
}
?>



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)