Remove keys from cache

时间秒杀一切 提交于 2019-12-11 06:36:53

问题


I'm using memcached and c++. I want to remove all keys from server using c++ api. It would be better to remove them without list of the keys.

There is function in documentation: memcached_dump and memcached_delete. First one returns the list of keys, and the second one - removes them.

But here is the quote from the docs of first function:

memcached_dump() is used to get a list of keys found in memcached(1) servers. Because memcached(1) does not guarentee to dump all keys you can not assume you have fetched all keys from the server.

The first question: any ways to fetch ALL keys and the second is: how to use these functions at all. There aren't any examples in documentation.

Thanks.


回答1:


Sounds like you want memcached_flush ?




回答2:


An elegant way to remove the memcached keys would be the use of basic delete command. But as we don't know which keys to delete, you ought to keep a log of the data being set in the memcached. You could dump these log along with their time-stamp in any data-store. By this procedure you would be able to delete keys with certain rules thereby providing to better control in the delete operation.




回答3:


Logging keys is a useful way of managing cache data when you need to be able to delete a bunch of keys. In addition, using a prefix can provide a way of managing the cached data as a whole.

function save($key,$data,$group){
    cache_log_key($group,$key);
    cache_save($application_prefix.$key,$data);
}

function deleteGroup($group){
    $loggedKeys = cache_get_log($group);
    foreach($loggedKeys as $key){
        cache_delete($application_prefix.$key);
    }    
    cache_delete_log($group);
}


来源:https://stackoverflow.com/questions/10830787/remove-keys-from-cache

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