Longhorn PHP 2025 - Speakers and Schedule Announced!

Memcache::flush

memcache_flush

(PECL memcache >= 1.0.0)

Memcache::flush -- memcache_flushサーバー上のすべての既存項目を消去する

説明

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

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
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.
up
6
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 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