0

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 !

asked Jan 23, 2020 at 20:37
1
  • Are you sure that cache comes from controller side ? try to stop loading layout and check the controller result again Commented Jan 23, 2020 at 20:48

1 Answer 1

0

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

answered Jan 24, 2020 at 0:59

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.