4

I have custom module add data to core_config_data.i want after save can auto clean cache. Any help? thks.

3 Answers 3

2

It is a bit late, but this answer is intended for those who will arrive here from Google, as myself.

To clean the cache after saving new value, you need to inject Cache Manager in the constructor, and then call 'flush' method in it with cache tag 'config' passed as a parameter.

Example:

use Magento\Framework\App\Cache\Manager as CacheManager; use Magento\Framework\App\Cache\Type\Config as CacheTypeConfig; . . $this->_cacheManager->clean([CacheTypeConfig::CACHE_TAG])

I couldn't manage to have it re-populated on the same request, but the next one is getting it right (meaning the updated value).

1

Try with this..

$command = 'php bin/magento cache:clean && php bin/magento cache:flush';
echo '<pre>' . shell_exec($command) . '</pre>';

Please be sure you can actually excecute php from the command line, else this will be useless. For windows you have to make sure you have added the php.exe to your PATH in the Environment Variables. Please see http://willj.co/2012/10/run-wamp-php-windows-7-command-line/

1
  • This would be bad practice since it sounds like this would be added into a custom module. Avoid shell commands and use the Magento API
    – scrowler
    Jul 4, 2016 at 8:45
1

use function clean($arrayCateTags) in \Magento\Framework\App\Cache

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.