PHP 8.5.0 Beta 2 available for testing

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

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

?>

添加备注

用户贡献的备注 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