Memcache expiration times

余生长醉 提交于 2019-12-11 07:29:37

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!