PHPerKaigi 2024


一些存储命令在发送时会包含一个失效值(与一个元素或一个客户端操作请求相关)到服务端。所有这类用法,实际发送的值可以 是一个 Unix 时间戳(自 1970 年 1 月 1 日起至失效时间的整型秒数),或者是一个从现在算起的以秒为单位的数字。对于后一种情况,这个 秒数不能超过 60×60×24×30(30 天时间的秒数);如果失效的值大于这个值,服务端会将其作为一个真实的 Unix 时间戳来处理而不是 自当前时间的偏移。

如果失效值被设置为 0(默认),此元素永不过期(但是它可能由于服务端为了给其他新的元素分配空间而被删除)。

add a note

User Contributed Notes 2 notes

valugi at gmail dot com
7 years ago
The fact that one sets an expiration time does not mean that the keys will expire at that particular time. I'm not sure what is happening in the background, if there is a process like a garbage collector that expire keys, but some function do not activate the expiration check and return the key as valid, for example `getAllKeys` is not atomic and returns even expired keys.

$memcached = new Memcached();
//waiting more than 10 sec
$data = $memcached->getAllKeys();
var_dump($data); // key will still be listed
$key = $memcached->get('key'); // will trigger the expiration
i dot caught dot air at gmail dot com
6 years ago
A TTL of n seconds will expire between n and n-1 seconds as memcache doesn't use a high-resolution clock internally.

This is important to consider if you're working with very short TTLs.

To Top