Please note that after flushing, you have to wait a certain amount of time (in my case < 1s) to be able to write to Memcached again. If you don't, Memcached::set() will return 1, although your data is in fact not saved.
Memcache::flush
(PECL memcache >= 1.0.0)
Memcache::flush — Limpia todos los valores existentes en el servidor
Descripción
bool Memcache::flush
( void
)
Memcache::flush() invalida inmediatamente todos los valores existentes. Memcache::flush() no libera recursos del sistema, solamente marca los valores como expirados, la memoria que ahora se ocupa será sobreescrita por los nuevos valores. También se puede usar la función memcache_flush().
Valores devueltos
Devuelve TRUE en caso de éxito o FALSE en caso de error.
Ejemplos
Ejemplo #1 Ejemplo de Memcache::flush()
<?php
/* API por procedimientos */
$memcache_obj = memcache_connect('memcache_host', 11211);
memcache_flush($memcache_obj);
/* API OO */
$memcache_obj = new Memcache;
$memcache_obj->connect('memcache_host', 11211);
$memcache_obj->flush();
?>
maarten d/ot manders a/t tilllate dotcom ¶
5 years ago
Anonymous ¶
5 years ago
From the memcached mailing list:
"The flush has a one second granularity. The flush will expire all items up to the ones set within the same second."
It is imperative to wait at least one second after flush() command before further actions like repopulating the cache. Ohterwise new items < 1 second after flush() would be invalidatet instantaneous.
Example:
<?php
$memcache->flush();
$time = time()+1; //one second future
while(time() < $time) {
//sleep
}
$memcache->set('key', 'value'); // repopulate the cache
?>
