Skip to content

Commit 7a50b2a

Browse files
committed
Revert "Remove unused/inactive purge prefixes command"
This reverts commit a72da44.
1 parent a72da44 commit 7a50b2a

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/HeaderEnum.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ enum HeaderEnum: string
66
{
77
case CACHE_TAG = 'Cache-Tag';
88
case CACHE_PURGE_TAG = 'Cache-Purge-Tag';
9+
case CACHE_PURGE_PREFIX = 'Cache-Purge-Prefix';
910
case CACHE_CONTROL = 'Cache-Control';
1011
case CDN_CACHE_CONTROL = 'CDN-Cache-Control';
1112
case SURROGATE_CONTROL = 'Surrogate-Control';

src/StaticCache.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,24 @@ public function purgeTags(string|StaticCacheTag ...$tags): void
292292
]);
293293
}
294294

295+
public function purgeUrlPrefixes(string ...$urlPrefixes): void
296+
{
297+
$urlPrefixes = Collection::make($urlPrefixes)->filter()->unique();
298+
299+
if ($urlPrefixes->isEmpty()) {
300+
return;
301+
}
302+
303+
Craft::info(new PsrMessage('Purging URL prefixes', [
304+
'urlPrefixes' => $urlPrefixes->all(),
305+
]), __METHOD__);
306+
307+
// TODO: make sure we don't go over max header size
308+
Helper::makeGatewayApiRequest([
309+
HeaderEnum::CACHE_PURGE_PREFIX->value => $urlPrefixes->implode(','),
310+
]);
311+
}
312+
295313
private function isCacheable(): bool
296314
{
297315
$response = Craft::$app->getResponse();

src/cli/controllers/StaticCacheController.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88

99
class StaticCacheController extends Controller
1010
{
11+
public function actionPurgePrefixes(string ...$prefixes): int
12+
{
13+
$this->do('Purging prefixes', function() use ($prefixes) {
14+
Module::getInstance()->getStaticCache()->purgeUrlPrefixes(...$prefixes);
15+
});
16+
17+
return ExitCode::OK;
18+
}
19+
1120
public function actionPurgeTags(string ...$tags): int
1221
{
1322
$this->do('Purging tags', function() use ($tags) {

0 commit comments

Comments
 (0)