flushmemcachedb

Memcache flush all does not empty slabs?


I am using the using the flush all command to delete all the key/value pair on my Memcache server.

While the values get deleted, there are two things I can't understand when looking at the Memcache server through phpMemcachedAdmin

  1. The memory usage is not reset to 0 after flushing it all. I still have 77% used and 22% wasted (just an example, but you get the spirit). How is that possible?

  2. All the previous slab with the previous items are still there. For example, looking at a specific slab would show all the previous key/value pairs, despite the flush all command. How is that possible?

Thanks


Solution

  • This happens because memcache flushes on read, not on write. When you flush_all, that operations is designed for performance: it just means anything read beyond that time will be instantly expired, even though it is still in the cache. It just updates a single number and then checks that on each fetch.

    This optimization significantly improves memcache performance. Imagine if several other people are searching or inserting at the same time as a flush.