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?
2 Answers
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.. Commented Dec 27, 2015 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) Commented Dec 27, 2015 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. Commented Dec 27, 2015 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. Commented Dec 27, 2015 at 11:37
-
Can you check on debug.log if perhaps another event invalidate the cache after your cleanup? Commented Dec 27, 2015 at 11:41
go into magento root folder using command
sudo php bin/magento cache:clean
run above command.
I hope this will help you.