PHP 8.4.0 RC4 available for testing

超时时间

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

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

添加备注

用户贡献的备注 2 notes

up
4
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();
$memcached->set('key','value',10);
//waiting more than 10 sec
sleep(20);
$data = $memcached->getAllKeys();
var_dump($data); // key will still be listed
$key = $memcached->get('key'); // will trigger the expiration
up
-1
i dot caught dot air at gmail dot com
7 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.

See https://github.com/memcached/memcached/issues/307
To Top