-
Notifications
You must be signed in to change notification settings - Fork 3
Description
The red "Edit Entry" sometimes ends up in Blitz or CDN cached versions of the site.
We should explore a few different options to prevent this from happening when content editors view the front-end of the site.
There are a few caching layers
- Blitz's caching (stored as files on the server or in Yii's Cache).
- CDN caching (Cloudflare or Cloudfront sitting in front of the site). These are separate and unaware of Blitz or Craft internals. All that the Blitz integration does is invalidate these caches when content changes.
- It's often possible to prevent these services from caching by passing the appropraite no-cache/store headers
Change to Viget.com module code (no-cache headers for admins)
Details:
Across a few sites that use this module with the Blitz plugin (e.g. ADC-AMH, Viget) sometimes the Edit Entry
button gets cached in the Blitz static cache for all users.
It was a misunderstanding that Blitz automatically does not cache or serve cached assets to signed-in users, but in looking at the source code the logic is as follows:
Blitz is only checking:
- is the site turned off but the user can see it anyway?
($user !== null) && (!Craft::$app->getIsLive() && !$user->can('accessSiteWhenSystemIsOff'))
- does the user have the debug toolbar open
($user !== null) && ($user->getPreference('enableDebugToolbarForSite'))
- does the page say not to cache it (admin area etc) using
(!empty($request->getParam('no-cache')))
- page has a token
($request->getToken() !== null && !$this->getIsGeneratorRequest())
During development, Viget developers (cough me) have the debug toolbar visible so the caching issue was not immediately evident or consistent. Seeing that this Blitz logic checks for the no-cache
header, add a no-cache header to all pages that show the Edit Entry button
Looking at the Craft 4 code for Response
there may be a public function setNoCacheHeaders()
or else the module might need to do something like
$request = Craft::$app->getRequest();
$request->setHeader('Pragma', 'no-cache', true);
Ref: