Page context menu: Purge from SSR cache

SsrPurgeItemProvider adds the item behind Clear cache for real pages (doktype < 199) whenever the purge endpoint is configured. The callback module posts the page uid to the new vitec_ssr_purge_page ajax route, which resolves the page path through the site router, purges it via SsrPurgeService (trigger contextmenu:username, logged as usual) and reports back as a toast notification.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
orascheandClaude Fable 5 committed 2026-11-09 21:10:30 +01:00
1 parent fa63871da7
commit 5b524bfce9
4 files changed
+132

No files matched your search

@@ -0,0 +1,71 @@
<?php
declare(strict_types=1);
namespace Evomedien\Vitec\ContextMenu;
use TYPO3\CMS\Backend\ContextMenu\ItemProviders\AbstractProvider;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Core\Environment;
/**
* Page tree context menu: "Purge from SSR cache" - evicts exactly this
* page from the SSR node's full-page cache, with toast feedback.
* Shown only for real pages and only while the purge endpoint is
* configured (var/vitec-ssr-purge.env).
*/
final class SsrPurgeItemProvider extends AbstractProvider
{
protected $itemsConfiguration = [
'ssrPurge' => [
'type' => 'item',
'label' => 'Purge from SSR cache',
'iconIdentifier' => 'actions-system-cache-clear-impact-medium',
'callbackAction' => 'ssrPurge',
],
];
public function canHandle(): bool
{
return $this->table === 'pages';
}
/**
* Below the core PageProvider (100): we run after it and splice our
* item into the finished menu, right behind "Clear cache".
*/
public function getPriority(): int
{
return 42;
}
public function addItems(array $items): array
{
if (!is_readable(Environment::getVarPath() . '/vitec-ssr-purge.env')) {
return $items;
}
$page = BackendUtility::getRecord('pages', (int)$this->identifier, 'uid,doktype');
if ($page === null || (int)$page['doktype'] >= 199) {
// Spacers, folders, recycler - nothing cached for those.
return $items;
}
$this->initDisabledItems();
$localItems = $this->prepareItems($this->itemsConfiguration);
if (isset($items['clearCache'])) {
$new = [];
foreach ($items as $key => $item) {
$new[$key] = $item;
if ($key === 'clearCache') {
$new = array_merge($new, $localItems);
}
}
return $new;
}
return array_merge($items, $localItems);
}
protected function getAdditionalAttributes(string $itemName): array
{
return ['data-callback-module' => '@evomedien/vitec/ssr-context-menu.js'];
}
}