Memcache小记
Memcache小记1) set, add, replace方法的异同点
set意思是"储存此数据",当key存在时会自动覆盖原先的值
add意思是"储存此数据,只在服务器*未*保留此键值的数据时” 当key存在时不会覆盖原先的值,缓存值失败,返回False
replace意思是"储存此数据,只在服务器*曾*保留此键值的数据时” 当key不存在时缓存失败,返回False,当key存在时覆盖原先的值
2) memcached和memcache的区别
memcached是缓存软件,带d指守护进程, memcache一般指memcached client
libmemcache一般是指memcached自带的include/lib
libmemcached是一个第三方封装的加强版的memcached client类库
php下有两个memcached client, 一个是php-memcached,依赖libmemcached, 一个php-memcache,无依赖
3) Memcache::flush具有1秒钟的粒度, 所以使用Memcache::flush时必须等待一秒钟之后才可以进行缓存操作, 否则任何在flush()之后1秒内缓存的项都将瞬间失效.
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 invalidated instantaneous.
Example:
<?php
$memcache->flush();
sleep(1);
$memcache->set('key', 'value'); // repopulate the cache
页:
[1]