Lazy Expiration in Memcached
I read this - How does the lazy expiration mechanism in memcached operate?
So I have a question. Is it possible/recommended to make a program myself that periodically checks for all items in memcached, sending GET requests for each item so that expired items are removed?
The reason I want this is because I want to have a proper control of the used percentage in Memcached. If that perc开发者_运维问答entage is near 100%, I will never be sure if I should add more memory, or if I should not worry because there are many expired items.
I use PHP, and unfortunately this doesn't return all the items in memcached (no clue why):
$allSlabs = $memcache->getExtendedStats('slabs');
foreach ($allSlabs as $server => $slabs) {
foreach ($slabs as $slabId => $slabMeta) {
$cdump = $memcache->getExtendedStats('cachedump', (int)$slabId);
foreach ($cdump as $keys => $arrVal) {
foreach ($arrVal as $key => $v) {
echo $key, "\n";
}
}
}
}
You should just use the eviction rate to see if you need to add more memory. The eviction stats will increase if memcached had to throw out an object in order to make room for storing the next one. (and you can look at the "reclaimed" stat to see the number of times we could reclaim the memory for an item to store a new item.
The code you suggest would jam down the server by dumping its content every now and then.
精彩评论