Merge pull request #2471 from creative-commoners/pulls/4.4/no-caching-on-previews-or-drafts

FIX Disable caching on page previews (CMSPreviews or stage=Stage)
This commit is contained in:
Robbie Averill 2019-08-22 14:09:11 +12:00 committed by GitHub
commit abf026c500
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 0 deletions

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)