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
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.
Actually, the easiest way to deallocate all values is restart memcached instance.
Try this
Mage::app()->getCacheInstance()->getFrontend()->getBackend()->clean(Zend_Cache::CLEANING_MODE_ALL);
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.
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