From c96062d9ac6409f6bae2e7fcd832018da673f318 Mon Sep 17 00:00:00 2001 From: bencroker Date: Tue, 5 Nov 2024 18:19:08 +0100 Subject: [PATCH] Fix URIs with query strings being cached --- src/services/CacheRequestService.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/services/CacheRequestService.php b/src/services/CacheRequestService.php index 6a1843b9..8f024511 100755 --- a/src/services/CacheRequestService.php +++ b/src/services/CacheRequestService.php @@ -251,9 +251,9 @@ public function getIsCacheableSiteUri(?SiteUriModel $siteUri): bool } if (Blitz::$plugin->settings->queryStringCaching == SettingsModel::QUERY_STRINGS_DO_NOT_CACHE_URLS) { - $allowedQueryString = $this->getAllowedQueryString($siteUri->siteId, $siteUri->uri); + $queryStringParams = $this->getQueryStringParams($siteUri->uri); - if ($allowedQueryString) { + if (!empty($queryStringParams)) { Blitz::$plugin->debug('Page not cached because a query string was provided with the query string caching setting disabled.', [], $url); return false; @@ -555,6 +555,17 @@ public function matchesQueryStringParams(int $siteId, string $param, array|strin return false; } + /** + * Returns the query string params of the URI. + */ + public function getQueryStringParams(string $uri): array + { + $queryString = parse_url($uri, PHP_URL_QUERY) ?: ''; + parse_str($queryString, $queryStringParams); + + return $queryStringParams; + } + /** * Returns the query string after processing the included and excluded query string params. */ @@ -564,8 +575,7 @@ public function getAllowedQueryString(int $siteId, string $uri): string return $this->allowedQueryStrings[$siteId][$uri]; } - $queryString = parse_url($uri, PHP_URL_QUERY) ?: ''; - parse_str($queryString, $queryStringParams); + $queryStringParams = $this->getQueryStringParams($uri); if (!$this->getIsCachedInclude($uri)) { foreach ($queryStringParams as $key => $value) {