有劚期限

æ ŧį´į”¨ã‚ŗãƒžãƒŗãƒ‰ãŽä¸­ãĢは、(ã‚ĸイテム単äŊã‚るいはクナイã‚ĸãƒŗãƒˆã‹ã‚‰čĻæą‚ã•ã‚ŒãŸæ“äŊœå˜äŊãŽ) 有劚期限をã‚ĩãƒŧバãƒŧãĢ送äŋĄã™ã‚‹ã‚‚ぎがありぞす。そぎようãĒ場合ãĢ原際ãĢ送られる値は、 Unix ã‚ŋイム (1970 åš´ 1 月 1 æ—ĨからぎįĩŒéŽį§’æ•°) ã‚ã‚‹ã„ã¯įžåœ¨æ™‚åˆģã‹ã‚‰ãŽį§’æ•°ã¨ãĒりぞす。 åžŒč€…ãŽå ´åˆã€æœ€å¤§ãŽį§’æ•°ã¯ 60*60*24*30 (30 æ—Ĩé–“ã‚’ã‚ã‚‰ã‚ã™į§’æ•°) ぞでとãĒりぞす。 ã‚‚ã—æœ‰åŠšæœŸé™ãŒãã‚Œã‚ˆã‚Šé•ˇã„å ´åˆã¯ã€įžåœ¨æ™‚åˆģからぎįĩŒéŽį§’数ではãĒく Unix ã‚ŋイムであるとã‚ĩãƒŧバãƒŧãĢãŋãĒされãĻしぞいぞす。

有劚期限を 0 (デフりãƒĢト) ãĢすると、 ã‚ĸイテムは期限切れãĢãĒらãĒくãĒりぞす (しかし、äģ–ぎã‚ĸã‚¤ãƒ†ãƒ į”¨ãŽå ´æ‰€ã‚’įĸēäŋã™ã‚‹ãŸã‚ãĢã‚ĩãƒŧバãƒŧから削除されることもありえぞす)。

īŧ‹add a note

User Contributed Notes 2 notes

up
6
valugi at gmail dot com Âļ
9 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
-2
i dot caught dot air at gmail dot com Âļ
8 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