0

I need to remove the cache from my Block class, even if it removes the cache from the entire page.

How could I do it?

2

1 Answer 1

1

You can implement the HTTP class and call the method setNoCacheHeaders, as you can see below.

use Magento\Framework\App\Response\Http;

public function myCustomMethod(){
    $this->response->setNoCacheHeaders();
    ...
}

It will implement this module below, which will set no-cache in the header.

Magento 2 remove cache from Block class

7
  • where should I call this method in block or in phtml file?
    – Mohit Rane
    May 7, 2020 at 4:34
  • In your Block class, inside the method that you are using. May 8, 2020 at 14:18
  • can you please add the code here?
    – Mohit Rane
    May 25, 2020 at 5:25
  • Hi @MohitRane, the code is above the image. May 25, 2020 at 14:37
  • yes, I know. But I can't see the code after max-age Is there any further code?
    – Mohit Rane
    May 26, 2020 at 4:56

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.