Memcache::flush
(PECL memcache >= 1.0.0)
Memcache::flush — Flush all existing items at the server
Description
bool Memcache::flush
( void
)
Memcache::flush() immediately invalidates all existing items. Memcache::flush() doesn't actually free any resources, it only marks all the items as expired, so occupied memory will be overwritten by new items. Also you can use memcache_flush() function.
Return Values
Returns TRUE
on success or FALSE
on failure.
Examples
Example #1 Memcache::flush() example
<?php
/* procedural API */
$memcache_obj = memcache_connect('memcache_host', 11211);
memcache_flush($memcache_obj);
/* OO API */
$memcache_obj = new Memcache;
$memcache_obj->connect('memcache_host', 11211);
$memcache_obj->flush();
?>
- Функция Memcache::add() - Add an item to the server
- Функция Memcache::addServer() - Add a memcached server to connection pool
- Функция Memcache::close() - Close memcached server connection
- Функция Memcache::connect() - Open memcached server connection
- Функция Memcache::decrement() - Decrement item's value
- Функция Memcache::delete() - Delete item from the server
- Функция Memcache::flush() - Flush all existing items at the server
- Функция Memcache::get() - Retrieve item from the server
- Функция Memcache::getExtendedStats() - Get statistics from all servers in pool
- Функция Memcache::getServerStatus() - Returns server status
- Функция Memcache::getStats() - Get statistics of the server
- Функция Memcache::getVersion() - Return version of the server
- Функция Memcache::increment() - Increment item's value
- Функция Memcache::pconnect() - Open memcached server persistent connection
- Функция Memcache::replace() - Replace value of the existing item
- Функция Memcache::set() - Store data at the server
- Функция Memcache::setCompressThreshold() - Enable automatic compression of large values
- Функция Memcache::setServerParams() - Changes server parameters and status at runtime
Коментарии
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
?>