I have a controller that only executes once after the cache is cleared. After that the response is always the same - cache is there instead of a new execution.

The class is extends\Magento\Framework\App\Action\Action:

class Index extends \Magento\Framework\App\Action\Action

What can I do inside this controller to get rid of the cache activity?

This is not related to any block, meaning that it cannot be done via xml cacheable=false option.

Thank you !

  • Are you sure that cache comes from controller side ? try to stop loading layout and check the controller result again
    – PЯINCƎ
    Commented Jan 23, 2020 at 20:48

1 Answer 1


You can add cache control header inside your controller

     * This action render random number for each request
    public function execute()
        $page = $this->pageFactory->create();
        //We are using HTTP headers to control various page caches (varnish, fastly, built-in php cache)
        $page->setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0', true);

        return $page;

Reference: https://devdocs.magento.com/guides/v2.3/extension-dev-guide/cache/page-caching/public-content.html

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.