Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Filament Cache Manager Laravel Package

binarybuilds/filament-cache-manager

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:
    composer require binarybuilds/filament-cache-manager
    
  2. Register the plugin in your Filament panel service provider:
    use BinaryBuilds\FilamentCacheManager\FilamentCacheManagerPlugin;
    
    public function panel(Panel $panel): Panel
    {
        return $panel
            ->plugin(FilamentCacheManagerPlugin::make());
    }
    
  3. Access the plugin via the Filament sidebar under "Cache Manager" (default location).

First Use Case

  • Quick cache clearing: Navigate to the plugin in Filament and select "Clear All Cache" to flush all Laravel caches (config, route, view, etc.) in one click.
  • Targeted cache clearing: Use the "Clear Specific Cache" section to clear individual cache types (e.g., routes, config, or compiled views) without affecting others.

Implementation Patterns

Workflows

  1. Development Workflow:

    • Clear caches during local development to avoid stale data:
      // Manually trigger cache clearing (if needed)
      Artisan::call('cache:clear');
      
    • Use the Filament UI to clear caches without running CLI commands, streamlining the dev loop.
  2. Deployment Workflow:

    • Integrate cache clearing into deployment scripts by triggering the plugin via Filament’s API (if exposed) or manually clear caches post-deploy.
    • Example post-deploy hook (using Laravel Forge/Envoyer):
      php artisan cache:clear
      
      Replace with a Filament API call if the plugin supports it (e.g., via a custom action).
  3. Multi-Environment Management:

    • Use the plugin’s environment-specific cache clearing (if extended) to target caches for staging/production separately.
    • Example: Add a custom action to the plugin to clear only production caches:
      FilamentCacheManagerPlugin::make()
          ->canClearProductionCache(true) // Hypothetical extension
          ->productionCacheKey('production_cache_key');
      

Integration Tips

  • 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'));
    

Gotchas and Tips

Pitfalls

  1. Permission Issues:

    • Ensure the authenticated user has the necessary permissions to clear caches. By default, the plugin may not enforce permissions, so explicitly restrict access:
      FilamentCacheManagerPlugin::make()
          ->canClearCache(fn (User $user) => $user->can('clear-cache'));
      
  2. Over-Clearing Caches:

    • Clearing caches too frequently (e.g., in a loop or automated script) can degrade performance. Use the plugin judiciously, especially in production.
  3. Missing Cache Drivers:

    • If using non-standard cache drivers (e.g., DynamoDB), the plugin may not detect them. Extend the plugin to include custom drivers:
      $plugin->addCacheDriver('dynamodb', 'DynamoDB Cache');
      
  4. Filament Panel Caching:

    • Clearing Laravel’s cache may not clear Filament’s internal caches (e.g., widget caches). Use Filament’s built-in cache commands:
      php artisan filament:cache-clear
      

Debugging

  • Cache Not Clearing:

    • Verify the cache driver is configured in config/cache.php. The plugin relies on Laravel’s cache system.
    • Check for errors in storage/logs/laravel.log after attempting to clear caches.
  • Plugin Not Appearing:

    • Ensure the plugin is registered in the correct panel service provider. If using multiple panels, register it in the intended panel.
    • Clear Filament’s view cache if the plugin UI doesn’t render:
      php artisan view:clear
      

Tips

  1. 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')),
        ]);
    
  2. 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',
            ],
        ]);
    
  3. Audit Logging: Log cache-clearing events for security/audit purposes. Extend the plugin to include logging:

    FilamentCacheManagerPlugin::make()
        ->logClearingEvents(true);
    
  4. 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
    
  5. Testing: Mock cache-clearing actions in tests to avoid unintended side effects:

    // In a test
    Artisan::shouldReceive('call')->with('cache:clear')->once();
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope