CakeFest 2024: The Official CakePHP Conference

有効期限

格納用コマンドの中には、(アイテム単位あるいはクライアントから要求された操作単位の) 有効期限をサーバーに送信するものがあります。そのような場合に実際に送られる値は、 Unix タイム (1970 年 1 月 1 日からの経過秒数) あるいは現在時刻からの秒数となります。 後者の場合、最大の秒数は 60*60*24*30 (30 日間をあらわす秒数) までとなります。 もし有効期限がそれより長い場合は、現在時刻からの経過秒数ではなく Unix タイムであるとサーバーにみなされてしまいます。

有効期限を 0 (デフォルト) にすると、 アイテムは期限切れにならなくなります (しかし、他のアイテム用の場所を確保するためにサーバーから削除されることもありえます)。

add a note

User Contributed Notes 2 notes

up
5
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
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.

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