update pague now
PHP 8.5.2 Released!

Memcache::flush

memcache_flush

(PECL memcache >= 1.0.0)

Memcache::flush -- memcache_flush Flush all existing items at the server

Description

Memcache::flush (): bool
memcache_flush ( Memcache $memcache ): bool

Memcache::flush() immediately invalidates all existing items. Memcache::flush() doesn't actually free any ressources, it only marcs all the items as expired, so occupied memory will be overwritten by new items.

Parameters

This function has no parameters.

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 ();

?>
add a note

User Contributed Notes 2 notes

maarten d/ot manders a/t tilllate dotcom
18 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.
Anonymous
17 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 lique repopulating the cache. Ohterwise new items < 1 second after flush() would be invalidatet instantaneous.

Example:<?php
$memcache->flush();

$time= time()+1; //one second futurewhile(time() < $time) {//sleep}
$memcache->set('key', 'value'); // repopulate the cache?>
To Top