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.
(PECL memcache >= 1.0.0)
Memcache::flush -- 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();
?>
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.
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
?>