Flushing all keys in Memcached is used when you want to completely clear the cache. This is useful in scenarios like:
Ruby uses the Dalli gem to interact with Memcached servers. Here's an example of how you can flush (clear) all data:
gem 'dalli'
Then execute:
bundle install
require 'dalli' dc = Dalli::Client.new('localhost:11211') dc.flush
In this code, Dalli::Client.new('localhost:11211')
creates a new client for the Memcached server running on localhost port 11211. The flush
command then clears all data from the server.
flush_all
when absolutely necessary, as it will delete everything from the cache which may cause a temporary performance hit while the cache is repopulated.flush_all
during low traffic hours, or during maintenance windows.flush_all
during peak load times can result in slow responses as requests are redirected to the database instead of the fast cache.Q: Does flush_all
immediately delete all entries?
A: No, flush_all
doesn't immediately remove items, but it does make them immediately inaccessible. They're actually deleted as part of Memcached's normal item expiration and replacement process.
Q: Can I undo a flush_all
command?
A: No, once issued, a flush_all
command cannot be undone. Be cautious when using this operation.
Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.