Why is the CurrItems metric in my Memcached cluster not decreasing when the keys expire?

This is an expected behavior. Memcached uses lazy expiration to remove keys when the time to live (TTL) has expired. That is, the key isn't removed from the node even though it's expired. However, when someone tries to access an expired key, Memcached checks the key, identifies that the key is expired, and then removes it from memory.

Memcached also removes expired keys if there are no free chunks or free pages left in the appropriate slab class to accommodate new keys. Memcached then removes the expired keys, or uses a least recently used (LRU) algorithm to evict keys if it can't find an already expired key. You'll see a decrease in the CurrItems metric after the keys are removed from memory.

The lru_crawler thread, which is an optional background thread, also clears expired keys from memory. The lru_crawler is a conservative task, and, even if enabled, has limited action over expired keys. Therefore, even with lru_crawler enabled, it can take some time for the CurrItems and keyspace memory to show a decrease in usage.

Use TTL to make a key available for particular amount of time. When the key becomes invalid (expires), it's eventually removed. Keys can't be retrieved after their expiration time.

Did this page help you? Yes | No

Back to the AWS Support Knowledge Center

Need help? Visit the AWS Support Center

Published: 2018-07-25