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
1 Answer 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.
answered May 6, 2020 at 17:44
-
where should I call this method in block or in phtml file?Mohit Rane– Mohit Rane2020年05月07日 04:34:58 +00:00Commented May 7, 2020 at 4:34
-
In your Block class, inside the method that you are using.Rafael Corrêa Gomes– Rafael Corrêa Gomes2020年05月08日 14:18:06 +00:00Commented May 8, 2020 at 14:18
-
can you please add the code here?Mohit Rane– Mohit Rane2020年05月25日 05:25:05 +00:00Commented May 25, 2020 at 5:25
-
Hi @MohitRane, the code is above the image.Rafael Corrêa Gomes– Rafael Corrêa Gomes2020年05月25日 14:37:21 +00:00Commented May 25, 2020 at 14:37
-
yes, I know. But I can't see the code after
max-ageIs there any further code?Mohit Rane– Mohit Rane2020年05月26日 04:56:44 +00:00Commented May 26, 2020 at 4:56
Explore related questions
See similar questions with these tags.
default
cacheable=falsein your layout xml? More info here: devdocs.magento.com/guides/v2.3/extension-dev-guide/cache/… Example: meetanshi.com/blog/…