ๆœ‰ๅŠนๆœŸ้™

ๆ ผ็ด็”จใ‚ณใƒžใƒณใƒ‰ใฎไธญใซใฏใ€(ใ‚ขใ‚คใƒ†ใƒ ๅ˜ไฝใ‚ใ‚‹ใ„ใฏใ‚ฏใƒฉใ‚คใ‚ขใƒณใƒˆใ‹ใ‚‰่ฆๆฑ‚ใ•ใ‚ŒใŸๆ“ไฝœๅ˜ไฝใฎ) ๆœ‰ๅŠนๆœŸ้™ใ‚’ใ‚ตใƒผใƒใƒผใซ้€ไฟกใ™ใ‚‹ใ‚‚ใฎใŒใ‚ใ‚Šใพใ™ใ€‚ใใฎใ‚ˆใ†ใชๅ ดๅˆใซๅฎŸ้š›ใซ้€ใ‚‰ใ‚Œใ‚‹ๅ€คใฏใ€ Unix ใ‚ฟใ‚คใƒ  (1970 ๅนด 1 ๆœˆ 1 ๆ—ฅใ‹ใ‚‰ใฎ็ตŒ้Ž็ง’ๆ•ฐ) ใ‚ใ‚‹ใ„ใฏ็พๅœจๆ™‚ๅˆปใ‹ใ‚‰ใฎ็ง’ๆ•ฐใจใชใ‚Šใพใ™ใ€‚ ๅพŒ่€…ใฎๅ ดๅˆใ€ๆœ€ๅคงใฎ็ง’ๆ•ฐใฏ 60*60*24*30 (30 ๆ—ฅ้–“ใ‚’ใ‚ใ‚‰ใ‚ใ™็ง’ๆ•ฐ) ใพใงใจใชใ‚Šใพใ™ใ€‚ ใ‚‚ใ—ๆœ‰ๅŠนๆœŸ้™ใŒใใ‚Œใ‚ˆใ‚Š้•ทใ„ๅ ดๅˆใฏใ€็พๅœจๆ™‚ๅˆปใ‹ใ‚‰ใฎ็ตŒ้Ž็ง’ๆ•ฐใงใฏใชใ Unix ใ‚ฟใ‚คใƒ ใงใ‚ใ‚‹ใจใ‚ตใƒผใƒใƒผใซใฟใชใ•ใ‚Œใฆใ—ใพใ„ใพใ™ใ€‚

ๆœ‰ๅŠนๆœŸ้™ใ‚’ 0 (ใƒ‡ใƒ•ใ‚ฉใƒซใƒˆ) ใซใ™ใ‚‹ใจใ€ ใ‚ขใ‚คใƒ†ใƒ ใฏๆœŸ้™ๅˆ‡ใ‚Œใซใชใ‚‰ใชใใชใ‚Šใพใ™ (ใ—ใ‹ใ—ใ€ไป–ใฎใ‚ขใ‚คใƒ†ใƒ ็”จใฎๅ ดๆ‰€ใ‚’็ขบไฟใ™ใ‚‹ใŸใ‚ใซใ‚ตใƒผใƒใƒผใ‹ใ‚‰ๅ‰Š้™คใ•ใ‚Œใ‚‹ใ“ใจใ‚‚ใ‚ใ‚Šใˆใพใ™)ใ€‚

๏ผ‹add a note

User Contributed Notes 2 notes

up
8
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
-1
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