Skip to content

Commit

Permalink
Fix URIs with query strings being cached
Browse files Browse the repository at this point in the history
  • Loading branch information
bencroker committed Nov 5, 2024
1 parent 438b5d1 commit c96062d
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/services/CacheRequestService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*/
Expand All @@ -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) {
Expand Down

0 comments on commit c96062d

Please sign in to comment.