略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: Memcache::flush

2024-04-25

Memcache::flush

(PECL memcache >= 1.0.0)

Memcache::flush清洗(删除)已经存储的所有的元素

说明

Memcache::flush(): bool

Memcache::flush()立即使所有已经存在的元素失效。方法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();

?>
add a noteadd a note

User Contributed Notes 2 notes

up
9
maarten d/ot manders a/t tilllate dotcom
14 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
14 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
?>

官方地址:https://www.php.net/manual/en/memcache.flush.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3