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 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值