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
full_page caches, not the
Whole cache flush decrease developer’s performance, so we can use
Before starting the installation, we need Node.js version 8.x or above as dependency.
Install For Specific Project
node.js, using below command
sudo apt-get install nodejs
Confirm node js installation using command
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
Confirm cache-clean installation using command
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
In your Magento directory, run
vendor/bin/cache-clean.js --watch or
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:
|(a for all)
|(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
|Clean Frontend static assets
|Clean Adminhtml static content
|Clean Generated code
mage2tv/magento-cache-clean globally run below command
composer global require --dev mage2tv/magento-cache-clean
verify where installed it in your pc or system in my case at => home/.config/composer/vendor/bin/cache-clean.js
set system path using this command
Now the installation process is completed, the next step is to run the cache command.
From any project’s root directory you can access using
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
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.