Reputation: 35497
Is it possible to obtain the remaining time left for a value stored in memcache?
Upvotes: 2
Views: 1452
Reputation: 10974
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
Upvotes: 1
Reputation: 13121
No. Memcache expire times are only a courtesy and not a guarantee. Any item in the cache may be purged at any time.
Upvotes: 2
Reputation: 90980
No it is not. If you want something like that, you need to encode it into your value.
Upvotes: 2