Memcache won't flush or clear memory

前端 未结 5 1416
天命终不由人
天命终不由人 2021-02-19 10:19

I\'ve been trying to clear my memcache as I\'m noticing the storage taking up almost 30% of server memory when using ps -aux.

So I ran the following php co

相关标签:
5条回答
  • 2021-02-19 10:33

    Colin, The Flush All command causes the cache to set all the expiration times to current. The next request for an existing key will return nothing and the record will be removed from the cache. Memcached does not have a separate process to clean expired items and uses a "Lazy" method which makes the process very lightweight and efficient. Because of this if you need to actually remove the cache and start from scratch, the only real way to accomplish this is to restart Memcached. A long workaround would be to dump all your keys, send the Flush All command, then loop through each key running a get against it, causing the record to be removed. Not 100% sure if this method would work but in theory sounds plausible.

    0 讨论(0)
  • 2021-02-19 10:43

    Actually, the easiest way to deallocate all values is restart memcached instance.

    0 讨论(0)
  • 2021-02-19 10:45

    Try this

    Mage::app()->getCacheInstance()->getFrontend()->getBackend()->clean(Zend_Cache::CLEANING_MODE_ALL);

    0 讨论(0)
  • 2021-02-19 10:47

    You really need to change the memcached settings so that it doesn't use up as much memory. When you start memcached, you can pass it the amount of memory it should use, in megabytes, using the -m flag. See its documentation for information.

    flush just invalidates all of the items in the cache, it doesn't command memcached to deallocate or unreserve the memory it is using. I doubt that you can command memcached to deallocate the memory it is using.

    0 讨论(0)
  • 2021-02-19 10:48

    You need to wait atleast 1 second after clearing memcache. otherwise items added less than one second will invalidate itself.

    Ex:

    $memcache->flush();
    
    $time = time()+1; //one second future
    while(time() < $time) {
    //sleep
    }
    $memcache->set('key', 'value'); // repopulate the cache 
    

    Look at this post, memcache flush issue

    0 讨论(0)
提交回复
热议问题