mohammedjalal99/filament-cache-plugin
Installation
composer require mohammedjalal99/filament-cache-plugin
Publish the config (if needed):
php artisan vendor:publish --provider="MohammedJalal99\FilamentCachePlugin\FilamentCachePluginServiceProvider"
Enable Plugin
Register the plugin in app/Providers/Filament/AdminPanelProvider.php:
return [
// ...
'plugins' => [
\MohammedJalal99\FilamentCachePlugin\FilamentCachePlugin::make(),
],
];
First Use Case
/admin/resources/posts). The plugin will automatically cache the page.X-Cache: HIT or X-Cache: MISS.config/filament-cache-plugin.php (adjust cache drivers, TTL, or excluded routes).Automatic Caching
PostsResource page will cache its list, create/edit forms, and related actions.Manual Cache Invalidation
use MohammedJalal99\FilamentCachePlugin\Facades\FilamentCache;
// Invalidate cache for a model (e.g., after update)
FilamentCache::invalidateModelCache(Post::class);
// Invalidate cache for a specific route
FilamentCache::invalidateRouteCache('/admin/resources/posts');
Conditional Caching
config/filament-cache-plugin.php:
'excluded_routes' => [
'admin/resources/posts/create',
'admin/pages/*',
],
Cache TTL Customization
'cache_ttl' => [
'default' => 300, // 5 minutes
'admin/resources/posts' => 600, // 10 minutes for Posts
],
Integration with Filament Events
ResourceCreated) to invalidate cache programmatically:
use Filament\Notifications\Actions\Action;
use Filament\Resources\Resource;
public static function getPages(): array
{
return [
'create' => CreatePage::make()->afterSave(function (Resource $resource) {
FilamentCache::invalidateModelCache($resource::class);
}),
];
}
Dynamic Cache Keys
FilamentCache::setCustomCacheKey(
'admin/resources/posts',
fn () => 'posts_' . request()->query('search')
);
Cache Dependencies
Cache::tags(['posts'])->put('posts_list', $data);
FilamentCache::invalidateCacheTags(['posts']);
Partial Page Caching
@cache directive for granular control:
@cache(['key' => 'posts_list'], now()->addMinutes(10))
{{ $postsTable }}
@endcache
Multi-Tenant Caching
FilamentCache::setCachePrefix('tenant_' . auth()->user()->tenant->id);
Cache Staleness
afterSave hooks).Route Exclusion Misconfiguration
/admin/auth/login).'excluded_routes' => [
'admin/auth/*', // Exclude all auth routes
],
Cache Driver Conflicts
file). Custom drivers (e.g., Redis) may need config:
'cache_driver' => env('CACHE_DRIVER', 'redis'),
config/cache.php.Debugging Cache Hits/Misses
'debug' => true,
Check browser console for FilamentCachePlugin logs or HTTP headers.Plugin Overrides
@cache directives).excluded_routes to avoid overlap.Log Cache Events
Add to AppServiceProvider:
FilamentCache::onCacheHit(fn ($key) => \Log::debug("Cache HIT: {$key}"));
FilamentCache::onCacheMiss(fn ($key) => \Log::debug("Cache MISS: {$key}"));
Clear Cache Programmatically
php artisan cache:clear
Or via Tinker:
FilamentCache::clear();
Inspect Cache Storage
file driver: Check storage/framework/cache.redis-cli to inspect keys:
redis-cli KEYS "filament*"
Custom Cache Strategies Override the default strategy by binding a custom class:
$this->app->bind(
\MohammedJalal99\FilamentCachePlugin\Contracts\CacheStrategy::class,
\App\Services\CustomCacheStrategy::class
);
Add Cache Widgets Extend the plugin to include Filament widgets for cache stats:
FilamentCachePlugin::make()->widgets([
\App\Widgets\CacheStatsWidget::class,
]);
Support for Filament Spas If using Filament Spas, configure the plugin to cache API responses separately:
'spa_routes' => [
'api/admin/posts',
],
Cache Warmup Pre-load cache during deployment:
php artisan filament-cache-plugin:warmup
How can I help you explore Laravel packages today?