0

I made a custom admin page and i am saving some configuration fields there and then am getting a notification from magento that i need to flush the cache. Is there any way to do that from the module itself? maybe put a hook where i save the config?

1

You can inject \Magento\Framework\App\CacheInterface as dependency and assign it to $_cacheManager in your constructor or get it from de $context (if you have) and then after save changes clean the related cache that way:

$this->_cacheManager->clean(array([tag1,tag2..tagN]));

You could find a complete implementation in Catalog\Product\Model

I guess you could use the "get" method of the ObjectManager to get the cache instance too, but I'm not sure if is a good practice.

  • This is great! 10x I'm just not sure about which tag i am supposed to use.. – Omry Zobel Dec 27 '15 at 10:30
  • It depends on what your configuration chances will affect, so you can start with config i guess (i don't remember the actual name) – MauroNigrele Dec 27 '15 at 11:08
  • I know for a fact it's config...but i'm not sure how to find out the name, the clean function always returns true, so that's not a good indication. I tried 'CONFIG', tried get all type names from \Magento\Framework\App\Cache\TypeListInterface ... and still didn't work. – Omry Zobel Dec 27 '15 at 11:12
  • I even tried calling \Magento\Backend\Controller\Adminhtml\Cache\FlushAll and then there is a notification that i flushed the cache..but still on the cache management page the cache is invalidated. – Omry Zobel Dec 27 '15 at 11:37
  • Can you check on debug.log if perhaps another event invalidate the cache after your cleanup? – MauroNigrele Dec 27 '15 at 11:41
0

go into magento root folder using command

sudo php bin/magento cache:clean

run above command.

I hope this will help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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