问题
Is it possible to obtain the remaining time left for a value stored in memcache?
回答1:
No. Memcache expire times are only a courtesy and not a guarantee. Any item in the cache may be purged at any time.
回答2:
No it is not. If you want something like that, you need to encode it into your value.
回答3:
Yes you can, but it is not a guaranteed value, since it can be purged. I would only advice to check this on a development environment, though.
function getMemcacheKeys() {
$memcache = new Memcache;
$memcache->connect('localhost', 11211) or die ("Could not connect to memcache server");
$list = array();
$allSlabs = $memcache->getExtendedStats('slabs');
foreach($allSlabs as $server => $slabs) {
foreach($slabs AS $slabId => $slabMeta) {
if (!is_numeric($slabId)) {
continue;
}
$cdump = $memcache->getExtendedStats('cachedump',(int)$slabId);
foreach($cdump AS $keys => $arrVal) {
if (!is_array($arrVal)) continue;
foreach($arrVal AS $k => $v) {
echo $k .' - '.date('H:i d.m.Y',$v[1]).'<br />';
}
}
}
}
}
Copied from: https://stackoverflow.com/a/7480534/338840
来源:https://stackoverflow.com/questions/4515770/memcache-expiration-times