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?

asked May 6, 2020 at 17:44
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

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.