binarybuilds/filament-cache-manager
composer require binarybuilds/filament-cache-manager
use BinaryBuilds\FilamentCacheManager\FilamentCacheManagerPlugin;
public function panel(Panel $panel): Panel
{
return $panel
->plugin(FilamentCacheManagerPlugin::make());
}
Development Workflow:
// Manually trigger cache clearing (if needed)
Artisan::call('cache:clear');
Deployment Workflow:
php artisan cache:clear
Replace with a Filament API call if the plugin supports it (e.g., via a custom action).Multi-Environment Management:
FilamentCacheManagerPlugin::make()
->canClearProductionCache(true) // Hypothetical extension
->productionCacheKey('production_cache_key');
Custom Cache Keys: Extend the plugin to support custom cache keys (e.g., for third-party caches like Redis or Memcached):
// In a service provider or plugin config
$plugin->customCacheKeys([
'redis' => 'cache:redis',
'memcached' => 'cache:memcached',
]);
Event-Based Clearing: Listen for cache-clearing events (if the plugin emits them) to trigger side effects, such as logging or notifying a team channel:
use BinaryBuilds\FilamentCacheManager\Events\CacheCleared;
CacheCleared::subscribe(function (CacheCleared $event) {
Log::info('Cache cleared by ' . auth()->id() . ' at ' . now());
});
Permissions: Restrict access to cache-clearing actions using Filament’s built-in policies or gates:
FilamentCacheManagerPlugin::make()
->canClearCache(fn (User $user) => $user->isAdmin());
Localization: Translate cache-related labels (e.g., "Clear Cache") if your Filament panel is multilingual:
FilamentCacheManagerPlugin::make()
->clearCacheLabel(__('filament-cache-manager::cache.clear'))
->clearAllLabel(__('filament-cache-manager::cache.clear_all'));
Permission Issues:
FilamentCacheManagerPlugin::make()
->canClearCache(fn (User $user) => $user->can('clear-cache'));
Over-Clearing Caches:
Missing Cache Drivers:
$plugin->addCacheDriver('dynamodb', 'DynamoDB Cache');
Filament Panel Caching:
php artisan filament:cache-clear
Cache Not Clearing:
config/cache.php. The plugin relies on Laravel’s cache system.storage/logs/laravel.log after attempting to clear caches.Plugin Not Appearing:
php artisan view:clear
Custom Actions: Add custom cache-clearing actions (e.g., "Clear Only Route Cache"):
FilamentCacheManagerPlugin::make()
->customActions([
Action::make('clear-routes')
->label('Clear Route Cache')
->action(fn () => Artisan::call('route:clear')),
]);
Batch Clearing: Group cache-clearing actions into logical batches (e.g., "Clear All Development Caches"):
FilamentCacheManagerPlugin::make()
->batchActions([
'clear-all' => [
'cache:clear',
'route:clear',
'config:clear',
],
]);
Audit Logging: Log cache-clearing events for security/audit purposes. Extend the plugin to include logging:
FilamentCacheManagerPlugin::make()
->logClearingEvents(true);
Performance Monitoring:
Monitor cache-clearing performance, especially in production. Use Laravel’s cache:clear command with --verbose to diagnose slow clears:
php artisan cache:clear --verbose
Testing: Mock cache-clearing actions in tests to avoid unintended side effects:
// In a test
Artisan::shouldReceive('call')->with('cache:clear')->once();
How can I help you explore Laravel packages today?