PHPackages                             mage-os/magento-cache-clean - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. mage-os/magento-cache-clean

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mage-os/magento-cache-clean
===========================

A faster drop in replacement for bin/magento cache:clean with file watcher

1.1.4(7mo ago)48194.8k↑12.8%5[1 issues](https://github.com/mage-os/magento-cache-clean/issues)[1 PRs](https://github.com/mage-os/magento-cache-clean/pulls)2BSD-3-ClauseClojureCI passing

Since Jul 2Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/mage-os/magento-cache-clean)[ Packagist](https://packagist.org/packages/mage-os/magento-cache-clean)[ Docs](https://github.com/mage-os/magento-cache-clean)[ GitHub Sponsors](https://github.com/vinai)[ RSS](/packages/mage-os-magento-cache-clean/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)DependenciesVersions (6)Used By (2)

> "You know, hope is a mistake. If you can't fix what's broken, you'll, uh... you'll go insane." - Max Rockatansky

Magento 2 Cache Clean
=====================

[](#magento-2-cache-clean)

A faster drop in replacement for `bin/magento cache:clean` with a file watcher.

The file watcher automatically cleans affected cache types in the Magento 2 cache during development. For example, if you make a change to a template, it only cleans the `block_html` and `full_page` caches, not the `config` or `layout` caches.

The project is only tested on MacOS and Linux. Please report bugs by opening an issue on the [GitHub issue tracker](https://github.com/mage-os/magento-cache-clean/issues).

Features
--------

[](#features)

- Supports file, redis and varnish cache backends
- Removes affected generated code classes when a source file is changed
- Zero configuration, all required information is read from `app/etc/env.php`
- Hotkeys for quick cache flushes while the watcher is running

Installation &amp; Updating
---------------------------

[](#installation--updating)

Installation:

```
composer require --dev mage-os/magento-cache-clean
```

Update:

```
composer update --dev mage-os/magento-cache-clean
```

The tool is commonly installed globally using `composer global require ...`.

Usage
-----

[](#usage)

In your Magento directory, run `vendor/bin/cache-clean.js --watch`

Press `Ctrl-C` to exit the watcher process.

The script can also be used as a faster drop in replacement of `bin/magento cache:clean`. For example:

```
vendor/bin/cache-clean.js config full_page
```

(It's quicker because the start-up time of `bin/magento` is so slow.)

There are several options to customize the behavior:

```
vendor/bin/cache-clean.js --help

Usage: cache-clean.js [options and flags] [cache-types...]
Clean the given cache types. If none are given, clean all cache types.

--directory|-d     Magento base directory
--watch|-w              Watch for file changes
--verbose|-v            Display more information
--no-flood-guard|-n     Disable the 5s debounce per cache type
--debug|-vv             Display too much information
--silent|-s             Display less information
--keep-generated|-k     Do not modify generated/code/
--file-list|-f    Process file list and exit
--version               Display the version
--help|-h               This help message

```

Usually I run the command once with the `--watch` switch (or `-w`) when I start development, and when I make a change that isn't automatically detected (yet), I run `vendor/bin/cache-clean.js` with the given cache types as a drop in replacement for `bin/magento cache:clean`.

### Hotkeys

[](#hotkeys)

When the watcher is running, segments of the cache can be cleaned with individual keystrokes:

KeyCache Segment(s)`c``config``b``block_html``l``layout``f``full_page``a`(a for all)`v`(v for view) `block_html`, `layout`, `full_page`, `translate``t``translate`There also are hotkeys to clean the static assets in the `A`dminhtml or the `F`rontend area or `I`ntegration test sandboxes or clean the `G`enerated code directory.

Clearing cache on production after deploy
-----------------------------------------

[](#clearing-cache-on-production-after-deploy)

The `--file-list ` argument is intended to be used to flush affected caches after deployment.
List the names of all changed files separated by a newline in the specified file.
Use the `--keep-generated` switch if you want files in `generated/code` to remain even if the PHP source files changed.

### Prerequisites:

[](#prerequisites)

- `node.js` (built on 18, but should work with older 10.x versions, too).
- It's a good idea to turn on all Magento caches `bin/magento cache:enable` to get the full benefit.

Known issues
------------

[](#known-issues)

- Currently, the watcher has to be restarted after a new theme is added, so it is added to the watchlist.
- Changes to files on NFS mounts (e.g. in vagrant) do **not** trigger the watches. Depending on a given setup, it might be possible to run the watcher on the host system instead.
- If you run the task in PHPStorm and the hotkeys are not working, search for actions by pressing `STRG+SHIFT+A`, then search for "registry...", then enable `nodejs.console.use.terminal` and restart the watcher process.
- Not tested a lot on Windows, please open an issue if you want to contribute.
- If you run into the error `Error NOSPC` or `ENOSPC: System limit for number of file watchers reached` on Linux, run the command:

```
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
```

- In Magento 2.1.0 - 2.3.3 there is a [bug](https://github.com/magento/magento2/pull/22228) that causes the full page cache records to be written to the `var/cache` directory instead of `var/page_cache`. This issue causes the cache cleaner behavior to be erratic. There is an easy workaround, namely removing all cache configuration from the default `app/etc/env.php`. The bug only affects the default config with the file system cache backend. Redis or Varnish are not affected. The bug will be fixed in the (currently upcoming) Magento 2.3.4 release.

More information
----------------

[](#more-information)

- Some words on using the watcher with [Docker &amp; VMs](https://github.com/mage-os/magento-cache-clean/blob/main/doc/docker-and-vm.md).
- [Running the watcher from code](https://github.com/mage-os/magento-cache-clean/blob/main/doc/using-via-code.md).
- The [rationale](https://github.com/mage-os/magento-cache-clean/blob/main/doc/rationale.md) explains the reasons I wrote the utility.
- How to [build](https://github.com/mage-os/magento-cache-clean/blob/main/doc/building.md) the tool from source.
- This package used to be called `mage2tv/magento-cache-clean`, but now it is part of Mage-OS, and thus the package name is `mage-os/magento-cache-clean`. The original package still works as it now is an empty wrapper that requires this package. Existing installations should continue to work.

Thanks
------

[](#thanks)

This script was inspired by [Timon de Groot](https://twitter.com/TimonGreat)'s [blog post](https://blog.timpack.org/speed-up-magento-development) where he describes the idea to use a file watcher in PHPStorm to call `redis-cli` to clear the complete cache whenever a XML file is modified. The only downside of that solution is that it always flushes the full cache and only works with redis.

Thank you also to everybody who gave feedback, shared ideas and helped test new features! This tool would be impossible without you!

Copyright &amp; License
-----------------------

[](#copyright--license)

Copyright 2019 - present by Vinai Kopp, distributed under the BSD-3-Clause license (see the [LICENSE](https://github.com/mage-os/magento-cache-clean/blob/main/LICENSE) file).

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance64

Regular maintenance activity

Popularity47

Moderate usage in the ecosystem

Community23

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~24 days

Total

5

Last Release

223d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1905417db5fbd31a61553b29bd441fdc66945da7cfb14f1b20a72275c68184e8?d=identicon)[vinai](/maintainers/vinai)

![](https://avatars.githubusercontent.com/u/100189073?v=4)[Mage-OS](/maintainers/mage-os-ci)[@mage-os-ci](https://github.com/mage-os-ci)

---

Top Contributors

[![Vinai](https://avatars.githubusercontent.com/u/72463?v=4)](https://github.com/Vinai "Vinai (472 commits)")[![mage-os-ci](https://avatars.githubusercontent.com/u/100189073?v=4)](https://github.com/mage-os-ci "mage-os-ci (5 commits)")[![rafaelstz](https://avatars.githubusercontent.com/u/610598?v=4)](https://github.com/rafaelstz "rafaelstz (2 commits)")[![peterjaap](https://avatars.githubusercontent.com/u/431360?v=4)](https://github.com/peterjaap "peterjaap (2 commits)")[![davidalger](https://avatars.githubusercontent.com/u/658281?v=4)](https://github.com/davidalger "davidalger (1 commits)")[![ryantfowler](https://avatars.githubusercontent.com/u/2093288?v=4)](https://github.com/ryantfowler "ryantfowler (1 commits)")[![thampe](https://avatars.githubusercontent.com/u/761744?v=4)](https://github.com/thampe "thampe (1 commits)")[![vesan-lw](https://avatars.githubusercontent.com/u/141248787?v=4)](https://github.com/vesan-lw "vesan-lw (1 commits)")[![DavidLambauer](https://avatars.githubusercontent.com/u/1841317?v=4)](https://github.com/DavidLambauer "DavidLambauer (1 commits)")

---

Tags

adobecommercecache-managerdev-utilitymage-osmagentomagento2utilitymagentodevelopment

### Embed Badge

![Health badge](/badges/mage-os-magento-cache-clean/health.svg)

```
[![Health](https://phpackages.com/badges/mage-os-magento-cache-clean/health.svg)](https://phpackages.com/packages/mage-os-magento-cache-clean)
```

###  Alternatives

[mage2tv/magento-cache-clean

This package has been migrated to mage-os/magento-cache-clean. Please switch over at your convenience.

5432.1M3](/packages/mage2tv-magento-cache-clean)[nette/utils

🛠 Nette Utils: lightweight utilities for string &amp; array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.

2.1k394.3M1.5k](/packages/nette-utils)[danielstjules/stringy

A string manipulation library with multibyte support

2.4k26.0M191](/packages/danielstjules-stringy)[voku/arrayy

Array manipulation library for PHP, called Arrayy!

4875.5M16](/packages/voku-arrayy)[vaimo/composer-patches

Applies a patch from a local or remote file to any package that is part of a given composer project. Patches can be defined both on project and on package level. Optional support for patch versioning, sequencing, custom patch applier configuration and patch command for testing/troubleshooting added patches.

2994.3M16](/packages/vaimo-composer-patches)[phpcsstandards/phpcsutils

A suite of utility functions for use with PHP\_CodeSniffer

6333.4M58](/packages/phpcsstandards-phpcsutils)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
