Refactor redirect cache busting into middleware

This commit is contained in:
Damian Mooyman 2018-06-14 14:11:31 +12:00
parent 92ab6b63b1
commit 6b8f63c4d5
No known key found for this signature in database
GPG Key ID: 78B823A10DE27D1A
4 changed files with 10 additions and 8 deletions

View File

@ -357,3 +357,7 @@ class PageController extends ContentController
Note this is different from `Vary: Accept-Encoding`,
which is important for compression (e.g. gzip), and usually added by
other layers such as Apache's mod_gzip.
* DataObject no longer automatically invokes `HTTP::register_modification_date`
with LastModified on construction. User code should instead invoke
`HTTPCacheControlMiddleware::singleton()->registerModificationDate()` explicitly.

View File

@ -769,5 +769,10 @@ class HTTPCacheControlMiddleware implements HTTPMiddleware, Resettable
// Even if publicCache(true) is specified, errors will be uncacheable
$this->disableCache(true);
}
// Don't cache redirects
if ($response->isRedirect()) {
$this->disableCache(true);
}
}
}

View File

@ -657,9 +657,6 @@ class RequestHandler extends ViewableData
*/
public function redirectBack()
{
// Don't cache the redirect back ever
HTTPCacheControlMiddleware::singleton()->disableCache(true);
// Prefer to redirect to ?BackURL, but fall back to Referer header
// As a last resort redirect to base url
$url = $this->getBackURL()

View File

@ -1812,13 +1812,9 @@ class Form extends ViewableData implements HasRequestHandler
/**
* Can the body of this form be cached?
*
* Figure out if we can cache this form
* - forms with validation shouldn't be cached, because their error messages won't be shown
* - forms with security tokens shouldn't be cached because security tokens expire
*
* @return bool
*/
public function canBeCached()
protected function canBeCached()
{
if ($this->getSecurityToken()->isEnabled()) {
return false;