0

I am bit confused, I am using the below method to clear the cache in Magento 2 programmatically, this method has an argument, and what value I need to pass in it?

method:

**public function flushCache(Version $subject)**
    {
        $types = array('config','layout','block_html','collections','reflection','db_ddl','eav','config_integration','config_integration_api','full_page','translate','config_webservice');
        
        foreach ($types as $type) {
            $this->cacheTypeList->cleanType($type);
        }
        foreach ($this->cacheFrontendPool as $cacheFrontend) {
            $cacheFrontend->getBackend()->clean();
        }
}
5
  • are you talking about which line from above code? Jun 28 '21 at 12:07
  • public function flushCache(Version $subject) { $types = array('config','layout','block_html','collections','reflection','db_ddl','eav','config_integration','config_integration_api','full_page','translate','config_webservice'); foreach ($types as $type) { $this->cacheTypeList->cleanType($type); } foreach ($this->cacheFrontendPool as $cacheFrontend) { $cacheFrontend->getBackend()->clean(); } }
    – Ajmalriyaz
    Jun 28 '21 at 12:26
  • @Dhiren Vasoya in the above snippet am asking about the first line, what attribute we need to pass in that.
    – Ajmalriyaz
    Jun 28 '21 at 12:27
  • Can you share complete file code on question. Jun 28 '21 at 12:27
  • @DhirenVasoya i have updated my question please take a look.
    – Ajmalriyaz
    Jun 28 '21 at 12:51
0

The code should work just fine if you remove that argument from the function and pass in nothing.

I have a similar script running on mine and it does not need a "Version" argument or object anywhere.

Edit: So the final function should look like this:

public function flushCache()
{
        $types = array('config','layout','block_html','collections','reflection','db_ddl','eav','config_integration','config_integration_api','full_page','translate','config_webservice');
        
        foreach ($types as $type) {
            $this->cacheTypeList->cleanType($type);
        }
        foreach ($this->cacheFrontendPool as $cacheFrontend) {
            $cacheFrontend->getBackend()->clean();
        }
}

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.