PHP 8.1.28 Released!

Memcache::flush

(PECL memcache >= 1.0.0)

Memcache::flushСбросить все существующие элементы на сервере

Описание

Memcache::flush(): bool

Memcache::flush() немедленно аннулирует все существующие элементы. Memcache::flush() фактически не освобождает ресурсы, а только помечает все элементы как истёкшие, поэтому занятая память будет перезаписана новыми элементами. Вы также можно использовать функцию memcache_flush().

Список параметров

У этой функции нет параметров.

Возвращаемые значения

Возвращает true в случае успешного выполнения или false, если возникла ошибка.

Примеры

Пример #1 Пример использования Memcache::flush()

<?php

/* процедурное API */
$memcache_obj = memcache_connect('memcache_host', 11211);

memcache_flush($memcache_obj);

/* объектно-ориентированное API */

$memcache_obj = new Memcache;
$memcache_obj->connect('memcache_host', 11211);

$memcache_obj->flush();

?>

add a note

User Contributed Notes 2 notes

up
9
maarten d/ot manders a/t tilllate dotcom
16 years ago
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.
up
6
Anonymous
16 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
?>
To Top