Chapters Close

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

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 https://www.mage2.tv

Flushing all caches

Usage

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.

Hotkeys

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

KeyCache Segment(s)
cconfig
bblock_html
llayout
ffull_page
a(a for all)
v(V for view) block_html, layout, full_page
ttranslate

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

KeyWork
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

I hope this comprehensive blog has been helpful. Please leave your comments below, and don’t hesitate to reach out if you require assistance with Magneto store development.

Reference From:

Git Hub: https://github.com/mage2tv/magento-cache-clean/blob/master/readme.md
Mage2tv:https://www.mage2.tv/content/fundamentals/magento-cli-tool/the-magento-cache-clean-js-file-watcher-utility/

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 3,470 subscribers

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

    Thank You!

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