Dragonfly Cloud announces new enterprise security features - learn more

Dragonfly

Question: How can you clear a distributed cache?

Answer

Clearing a distributed cache typically involves deleting its entries, either one at a time or all at once. The method to do so however depends on the specific caching system you are using. Here are examples for three popular systems: Redis, Memcached, and Apache Ignite.

Redis

To delete all keys from all databases in Redis, you use the FLUSHALL command.

redis-cli FLUSHALL

If you want to delete all keys from the currently selected database (default is database 0), you use the FLUSHDB command.

redis-cli FLUSHDB

Memcached

For memcached, you can invalidate all existing cache items using the flush_all command. Below is an example of how to flush everything from a server running on localhost on port 11211.

echo 'flush_all' | nc localhost 11211

This command does not remove items immediately, but rather invalidates them - they will be removed as and when Memcached needs to reclaim memory.

Apache Ignite

With Apache Ignite, you can clear caches with the removeAll() method, which removes all entries from cache.

IgniteCache cache = ignite.cache("myCache");
cache.removeAll();

Remember that clearing cache should be done carefully, considering its impact on your application's performance and functionality.

Was this content helpful?

Other Common In Memory Questions (and Answers)

White Paper

Free System Design on AWS E-Book

Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.

Free System Design on AWS E-Book

Switch & save up to 80% 

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement. Instantly experience up to a 25X boost in performance and 80% reduction in cost