diff --git a/code/Controllers/ContentController.php b/code/Controllers/ContentController.php index 265511c8..31d5e4f6 100644 --- a/code/Controllers/ContentController.php +++ b/code/Controllers/ContentController.php @@ -8,6 +8,7 @@ use SilverStripe\Control\Director; use SilverStripe\Control\HTTPRequest; use SilverStripe\Control\HTTPResponse; use SilverStripe\Control\HTTPResponse_Exception; +use SilverStripe\Control\Middleware\HTTPCacheControlMiddleware; use SilverStripe\Core\Convert; use SilverStripe\Core\Injector\Injector; use SilverStripe\Core\Manifest\ModuleManifest; @@ -139,6 +140,13 @@ class ContentController extends Controller { parent::init(); + // In the CMS Preview or draft contexts, we never want to cache page output. + if ($this->getRequest()->getVar('CMSPreview') === '1' + || $this->getRequest()->getVar('stage') === Versioned::DRAFT + ) { + HTTPCacheControlMiddleware::singleton()->disableCache(true); + } + // If we've accessed the homepage as /home/, then we should redirect to /. if ($this->dataRecord instanceof SiteTree && RootURLController::should_be_on_root($this->dataRecord)