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 againPЯINCƎ– PЯINCƎ ♦2020年01月23日 20:48:09 +00:00Commented 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
Explore related questions
See similar questions with these tags.