Skip to content

Commit 7ee35b7

Browse files
committed
Improve cacheable action request checks
1 parent 0708e02 commit 7ee35b7

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release Notes for Blitz
22

3+
## 5.11.1 - 2025-05-19
4+
5+
- Improved checks for cacheable action requests.
6+
37
## 5.11.0 - 2025-05-19
48

59
- Added a [Datastar](https://putyourlightson.com/plugins/datastar) integration that makes it possible to cache and serve streamed responses.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "putyourlightson/craft-blitz",
33
"description": "Intelligent static page caching for creating lightning-fast sites.",
4-
"version": "5.11.0",
4+
"version": "5.11.1",
55
"type": "craft-plugin",
66
"homepage": "https://putyourlightson.com/plugins/blitz",
77
"license": "proprietary",

src/services/CacheRequestService.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public function getIsCacheableRequest(): bool
134134
}
135135

136136
if ($request->getIsActionRequest()
137-
&& !Blitz::$plugin->settings->cacheActionRequests
137+
&& !$this->getIsCacheableActionRequest()
138138
) {
139139
return false;
140140
}
@@ -216,7 +216,10 @@ public function getIsCacheableSiteUri(?SiteUriModel $siteUri): bool
216216

217217
$uri = mb_strtolower($siteUri->uri);
218218

219-
if (Blitz::$plugin->settings->onlyCacheLowercaseUris && $uri !== $siteUri->uri) {
219+
if (Blitz::$plugin->settings->onlyCacheLowercaseUris
220+
&& $uri !== $siteUri->uri
221+
&& !$this->getIsCacheableActionRequest()
222+
) {
220223
Blitz::$plugin->debug('Page not cached because the URI contains uppercase characters.', [], $siteUri->uri);
221224

222225
return false;
@@ -251,7 +254,7 @@ public function getIsCacheableSiteUri(?SiteUriModel $siteUri): bool
251254
// Ignore URIs that contain `index.php` but that are not action requests
252255
$generalConfig = Craft::$app->getConfig()->getGeneral();
253256
$pattern = '/index\.php(?!\?' . preg_quote($generalConfig->pathParam) . '=' . preg_quote($generalConfig->actionTrigger) . '\/)/';
254-
if (preg_match($pattern, $uri, $m)) {
257+
if (preg_match($pattern, $uri)) {
255258
Blitz::$plugin->debug('Page not cached because the URL contains `index.php`.', [], $url);
256259

257260
return false;
@@ -270,7 +273,9 @@ public function getIsCacheableSiteUri(?SiteUriModel $siteUri): bool
270273
return false;
271274
}
272275

273-
if (Blitz::$plugin->settings->queryStringCaching === SettingsModel::QUERY_STRINGS_DO_NOT_CACHE_URLS) {
276+
if (Blitz::$plugin->settings->queryStringCaching === SettingsModel::QUERY_STRINGS_DO_NOT_CACHE_URLS
277+
&& !$this->getIsCacheableActionRequest()
278+
) {
274279
$queryStringParams = QueryStringHelper::getValidQueryStringParams($siteUri->uri);
275280

276281
if (!empty($queryStringParams)) {
@@ -342,6 +347,17 @@ public function getIsDynamicInclude(string $uri = null): bool
342347
return false;
343348
}
344349

350+
/**
351+
* Returns whether this is a cacheable action request.
352+
*
353+
* @since 5.11.1
354+
*/
355+
public function getIsCacheableActionRequest(): bool
356+
{
357+
return Craft::$app->getRequest()->getIsActionRequest()
358+
&& Blitz::$plugin->settings->cacheActionRequests;
359+
}
360+
345361
/**
346362
* Returns whether this is a generator request.
347363
*

0 commit comments

Comments
 (0)