Chapters Close

How to use cache-clean.js watcher utility in Magento 2?

Jun 13th, 2019 3 min to read

In this article you will be learning about how can use cache-clean.js watcher utility in Magento 2.

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.

Whole cache flush decrease developer’s performance, so we can use mage2tv/magento-cache-clean

Before starting the installation, we need Node.js version 8.x or above as dependency.

Install For Specific Project

Step 1

Install the node.js, using below command sudo apt-get install nodejs

Confirm node js installation using command node -v

Step 2

Now install mage2tv/magento-cache-clean  for specific project, go at root directory of your project and run below command
composer require --dev mage2tv/magento-cache-clean

Step 3

Confirm cache-clean installation using command vendor/bin/cache-clean.js

If you get the error Error NOSPC on Linux, run the command:

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

After successfully installation you get output Like:

Release 0.0.42 sponsored by

Flushing all caches


In your Magento directory, run vendor/bin/cache-clean.js --watch or -w
Now watch is start, Press Ctrl+C to exit the watcher process.
The file watcher automatically cleans affected cache types, watch will show notification in the terminal about the specific cache clean and recompiles the changes simultaneously.


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

KeyCache Segment(s)
a(a for all)
v(V for view) block_html, layout, full_page

There also are hotkeys to clean the static assets in the Adminhtml or the Frontend area or clean the Generated code directory

F Clean Frontend static assets
A Clean Adminhtml static content
G Clean Generated code

Install Globally

Step 1

Now install mage2tv/magento-cache-clean globally run below command
composer global require --dev mage2tv/magento-cache-clean

Step 2

verify where installed it in your pc or system in my case at => home/.config/composer/vendor/bin/cache-clean.js

Step 3

set system path using this command
export PATH="$PATH:$HOME/.config/composer/vendor/bin"

Now the installation process is completed, the next step is to run the cache command.

Step 4

From any project’s root directory you can access using  cache-clean.js

From out-off magento root directory can access using full directory path cache-clean.js -d ./magento230
Here -d or –directory for Magento Base Directory, magento230 is project name

Note: For globally installation can start watch using  cache-clean.js -w or cache-clean.js -d ./magentodirectory -w, For specific installation using vendor/bin/cache-clean.js -w

Reference From:

Git Hub:

Speak your Mind

Post a Comment

Got a question? Have a feedback? Please feel free to leave your ideas, opinions, and questions in the comments section of our post! ❤️

* This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Grow your online business like 4,772 subscribers

    * This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

    Thank You!

    We are reviewing your submission, and will be in touch shortly.