Skip to content
Memcached

flush_all — Invalidate Everything

Logically invalidate all keys instantly (lazy deletion).

By EZ4Code Team
flush_allinvalidationnamespace

Code

# Invalidate ALL keys immediately (logically)
flush_all
# OK

# Delayed invalidation (after N seconds)
flush_all 60
# OK
# keys still readable for 60s, then ignored

# Verify
get user:42
# END  <- returns nothing

# Python
from pymemcache.client.base import Client
c = Client(("localhost", 11211))
c.flush_all()

# WARNING: flush_all is global — affects ALL keys, not a namespace.
# There is no "delete pattern *" in Memcached.
# Namespacing trick: include a version prefix in keys, bump version to "flush"
#   user:v3:42   <- bump v3 -> v4 to logically invalidate all user:* keys
#   (old keys expire naturally or get evicted)

# Also: flush_all does NOT free memory immediately — items are
# removed lazily as they're requested or evicted. Restart the
# daemon to actually reclaim RSS.

Explanation

flush_all marks every key as invalid instantly (it bumps an internal generation counter); the actual memory is reclaimed lazily on subsequent gets or via eviction. Use it for cache warmups, test resets, or emergency clears. There's no built-in pattern deletion or namespace invalidation — emulate it by versioning your key prefix ("user:v3:42" → "user:v4:42") and bumping the version. flush_all N delays invalidation by N seconds. Be cautious in shared deployments — it clears the whole instance, not just your app's keys.

More Memcached Snippets