I use a module which create a route with a non cacheable block in his layout. The page is not cached, like described in http://devdocs.magento.com/guides/v2.1/extension-dev-guide/cache/page-caching/public-content.html
But on some conditions the module made a forward('defaultNoRoute'), then the cms 404 page layout is loaded and the page cached, then every next request gets the 404 cached page !!
try to add this before the forward
$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);
but it load the entire layout before forward, it can cause some troubles, i don't find it very clean ...
Is there any other suggestion to avoid page cache 404 forward ?