Skip to content

Commit

Permalink
Handle reaching of wildcard urls
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmitchell committed Feb 7, 2024
1 parent 1578126 commit 4526c2f
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/StaticCaching/Cachers/AbstractCacher.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,19 @@ public function invalidateUrls($urls)
*/
public function recacheUrls($urls)
{
collect($urls)->each(fn ($url) => is_array($url) ? $this->recacheUrl(...$url) : $this->recacheUrl($url));
collect($urls)
->map(fn ($url) => is_array($url) ? $url : [$url, null])
->each(function ($parts) {
[$path, $domain] = $parts;

if (Str::contains($path, '*')) {
$this->recacheWildcardUrl($path, $domain);

return;
}

$this->recacheUrl($path, $domain);
});
}

/**
Expand All @@ -278,6 +290,28 @@ public function recacheUrl($path, $domain = null)
StaticRecacheJob::dispatch($path, $domain);
}

/**
* Recache a wildcard URL.
*
* @param string $wildcard
* @param string|null $domain
*/
protected function recacheWildcardUrl($wildcard, $domain = null)
{
// Remove the asterisk
$wildcard = substr($wildcard, 0, -1);

if (! $domain) {
[$wildcard, $domain] = $this->getPathAndDomain($wildcard);
}

$this->getUrls($domain)->filter(function ($url) use ($wildcard) {
return Str::startsWith($url, $wildcard);
})->each(function ($url) use ($domain) {
$this->recacheUrl($url, $domain);
});
}

/**
* Determine if a given URL should be excluded from caching.
*
Expand Down

0 comments on commit 4526c2f

Please sign in to comment.