Fresh Free Preview

Differences between cache clean and flush in Magento

Video Lesson: Differences between cache clean and flush in Magento

In Magento, use cache:clean to remove specific cache types and cache:flush to clear all cache storage.

Published 1 day ago

Share with colleagues:

Lesson Content

When clearing Magento's cache, you've probably noticed two similar-looking commands: cache:clean and cache:flush. They might seem interchangeable at first glance, but there's a crucial difference that can save you from accidentally nuking your entire cache when you only meant to clear one type.

The key difference

Here's what each command actually does:

  • cache:clean [type] surgically removes only the specified cache types

  • cache:flush [type] takes a sledgehammer approach and clears the entire storage backend

That second one is where things get interesting (and potentially problematic).

Why flush can be dangerous

Magento stores multiple cache types in the same physical location. If you're using filesystem caching, they all live together in var/cache. If you're using Redis, multiple cache types often share the same database.

So when you run something like:

bin/magento cache:flush config

You're not just flushing the config cache. You're flushing everything that shares storage with the config cache. That means you are not only flushing the config cache, but also the block and layout caches.

Note: The full_page cache is stored in a different storage location than the default cache, so it will not be flushed when this command is executed.

This is particularly painful in production environments where you've built up a nice warm cache. One misguided flush command can cause your store to rebuild everything from scratch, rather than selectively clearing a specific type.

Best practices

The solution is simple: just stick with cache:clean if you want to clear a specific cache type:

bin/magento cache:clean config

This clears only the configuration cache, leaving all of the other caches intact.

The only time you'd want to use cache:flush is when you genuinely need to clear everything, such as after a major deployment, or when troubleshooting stubborn cache issues.

Even then, you're better off using:

bin/magento cache:flush

Without specifying a type, at least your intent is clear: you meant to clear everything.

A design flaw worth knowing

The behavior of cache:flush [type] is a design flaw in Magento's core. It's confusing and destructive in ways that catch even experienced developers off guard. The command suggests that it flushes only one cache type, but it actually flushes an entire storage backend.

Until (and if) this gets fixed, treat cache:flush [type] as deprecated in your workflow. There's no good reason to use it when cache:clean [type] does exactly what you'd expect without the collateral damage.