mage2tv / magento-cache-clean

A faster drop in replacement for bin/magento cache:clean with file watcher
BSD 3-Clause "New" or "Revised" License
531 stars 63 forks source link

Cache clean fails with custom cache backend #111

Closed vesan-lw closed 1 year ago

vesan-lw commented 1 year ago

The error: No cache_dir property present in file cache backend_options

image

How to reproduce: set custom cache backend setting in app/etc/env.php

image

The reason: hardcoded Magento\Framework\Cache\Backend\Redis in vendor/mage2tv/magento-cache-clean/bin/cache-clean.js file.

Custom class extends \Magento\Framework\Cache\Backend\Redis so that it could detected by instanceof.

Vinai commented 1 year ago

Hey, Thanks for opening the issue. Using instanceof isn't an option because of the nodejs runtime.

There are some places where the parent or implemented interfaces of a php class are determined using a regex, but this is currently not the case for the cache backend.

A custom cache backend is a rare use-case. I'll consider maybe adding support at some time. If you want to more quickly, please open a PR.

vesan-lw commented 1 year ago

Hi Vinai,

Could it be a quick temporary fix like, for example, add condition - if no cache_dir but port is set then consider it's a redis cache but not files cache. What do you think? In the future is could be rebuilt to instanceof using php cli script which will take class name as parameter and check the instance of the class

vesan-lw commented 1 year ago

sorry, closed accidentally, opening back

vesan-lw commented 1 year ago

One more option could be: unuglify cache-clean.js so that it could be easily patched with an additional line to the "case" statement

Vinai commented 1 year ago

You can make an unminified and unbundled build by running installing the build deps (clojure) and running make debug-build

vesan-lw commented 1 year ago

no clear, we have regular composer package, how to make it unminified after composer install?

Vinai commented 1 year ago

You can't unminify it, but you can create a new unminified build yourself.

You first need to install clojure.
Then you can make any required changes to the source code, and compile a new unminified build by running make debug-build.

If you run make install-debug it will create a debug-build and also install it in your local .composer/vendor/mage2tv/magento-cache-clean directory.

The make commands have to be run in the git project, so if you use the composer package in vendor/mage2tv/magento-cache-clean

vesan-lw commented 1 year ago

According to our CI/CD all packages need to be assembled by composer install so it can't build debug version during deployment. Could you check a small PR I've created?

Vinai commented 1 year ago

I've tested the change and it works well. One small cosmetic change request, then I'll be happy to merge and tag a release!

Vinai commented 1 year ago

Closed via #112

Vinai commented 1 year ago

Released as 1.0.50 - thanks again!

vesan-lw commented 1 year ago

Nice. Thank you!