FIX Disable caching on page previews (CMSPreviews or stage=Stage)

This commit is contained in:
Garion Herman 2019-08-22 13:33:30 +12:00
parent d7e64199a7
commit 8e3072922f

View File

@ -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)