Keep the public site readable after import (nbsp, highlighter, wrapping code, compact pager) and finish the admin extras already in this tree: sticky levels, preview, page cache, and live llms.txt. Co-authored-by: Cursor <cursoragent@cursor.com>
94 lines
2.6 KiB
PHP
94 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Filament\Pages;
|
|
|
|
use App\Blog\Support\PageCacheMiddleware;
|
|
use App\Models\Setting;
|
|
use Filament\Actions\Action;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Pages\Page;
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
class PageCache extends Page
|
|
{
|
|
protected static \UnitEnum|string|null $navigationGroup = '管理';
|
|
|
|
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-bolt';
|
|
|
|
protected static ?string $navigationLabel = '页面缓存';
|
|
|
|
protected static ?string $title = '页面缓存';
|
|
|
|
protected static ?string $slug = 'page-cache';
|
|
|
|
protected static ?int $navigationSort = 20;
|
|
|
|
protected string $view = 'filament.pages.page-cache';
|
|
|
|
/**
|
|
* @return array{hits: int, misses: int, count: int, rate: float, ttl: int}
|
|
*/
|
|
public function getStatsProperty(): array
|
|
{
|
|
return [
|
|
...PageCacheMiddleware::stats(),
|
|
'ttl' => (int) config('blog.page_cache_ttl', 300),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return list<array{key: string, url: string, cached_at: string}>
|
|
*/
|
|
public function getEntriesProperty(): array
|
|
{
|
|
return PageCacheMiddleware::entries();
|
|
}
|
|
|
|
public function flushPageCache(): void
|
|
{
|
|
PageCacheMiddleware::flush();
|
|
Notification::make()->title('前台页面缓存已清空')->success()->send();
|
|
}
|
|
|
|
public function flushAllCache(): void
|
|
{
|
|
PageCacheMiddleware::flush();
|
|
Setting::flushCache();
|
|
Cache::flush();
|
|
Notification::make()->title('全部缓存已清空')->success()->send();
|
|
}
|
|
|
|
public function resetStats(): void
|
|
{
|
|
PageCacheMiddleware::resetStats();
|
|
Notification::make()->title('命中统计已重置')->success()->send();
|
|
}
|
|
|
|
public function forgetEntry(string $key): void
|
|
{
|
|
PageCacheMiddleware::forget($key);
|
|
Notification::make()->title('已删除这条缓存')->success()->send();
|
|
}
|
|
|
|
protected function getHeaderActions(): array
|
|
{
|
|
return [
|
|
Action::make('resetStats')
|
|
->label('重置统计')
|
|
->color('gray')
|
|
->action(fn () => $this->resetStats()),
|
|
Action::make('flushPageCache')
|
|
->label('清空前台缓存')
|
|
->color('warning')
|
|
->action(fn () => $this->flushPageCache()),
|
|
Action::make('flushAllCache')
|
|
->label('清空全部缓存')
|
|
->color('danger')
|
|
->requiresConfirmation()
|
|
->action(fn () => $this->flushAllCache()),
|
|
];
|
|
}
|
|
}
|