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 Clear Cache Laravel Package

cms-multi/filament-clear-cache

Adds a “Clear Cache” button to your Filament admin toolbar so you can quickly run cache-clearing commands without leaving the panel. Supports Filament v2–v5 (via plugin versions) and configurable via a publishable config.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Install the package:
    composer require cms-multi/filament-clear-cache
    
  2. Register the plugin in your Filament panel configuration (e.g., app/Providers/Filament/AdminPanelProvider.php):
    use CmsMulti\FilamentClearCache\FilamentClearCachePlugin;
    
    public function panel(Panel $panel): Panel
    {
        return $panel
            ->plugins([
                FilamentClearCachePlugin::make(),
            ]);
    }
    
  3. First use case: Immediately see a "Clear Cache" button in the Filament admin toolbar. Clicking it triggers optimize:clear and refreshes the page.

Implementation Patterns

Core Workflow

  1. Default Behavior:

    • The plugin adds a toolbar button that executes php artisan optimize:clear when clicked.
    • A notification confirms cache clearance, and the UI updates via Livewire events.
  2. Conditional Activation:

    • Restrict visibility to specific environments (e.g., local, staging):
      FilamentClearCachePlugin::make()
          ->enabled(app()->environment(['local', 'staging']))
      
  3. Custom Commands:

    • Extend cache-clearing logic by adding custom Artisan commands:
      use CmsMulti\FilamentClearCache\Facades\FilamentClearCache;
      
      FilamentClearCache::addCommand('page-cache:clear');
      
    • Register in a service provider’s boot() method.
  4. Livewire Integration:

    • Trigger UI updates programmatically (e.g., after cache-heavy operations):
      // Livewire v3+
      $this->dispatch('clearCacheIncrement')->to(\CmsMulti\FilamentClearCache\Http\Livewire\ClearCache::class);
      
  5. Translation Support:

    • Localize tooltips and labels using Filament’s translation system (e.g., filament-clear-cache::clear-cache).

Integration Tips

  • Avoid Overuse: Cache clearance is resource-intensive. Use sparingly (e.g., post-deployment or during debugging).
  • Combine with Other Tools: Pair with laravel-debugbar to monitor cache impact.
  • Environment-Specific Logic: Disable in production unless absolutely necessary (e.g., via enabled()).

Gotchas and Tips

Pitfalls

  1. Performance Impact:

    • Clearing cache during peak traffic may cause downtime. Schedule via cron or use enabled() to restrict access.
    • Fix: Use php artisan optimize:clear --no-interaction in scripts or CI/CD pipelines.
  2. Livewire Caching:

    • Livewire components may retain stale data post-clearance. Force a redirect after clearing:
      return redirect()->back()->with('success', 'Cache cleared!');
      
  3. Command Conflicts:

    • Custom commands with parameters (e.g., route-cache:clear --tags=admin) may fail silently.
    • Fix: Use absolute paths or wrap in a custom Artisan handler.
  4. Visibility on Simple Pages:

    • The button hides automatically on non-admin pages (since v3.0.3), but may reappear if misconfigured.
    • Debug: Check config/filament-clear-cache.php for visible settings.

Debugging

  • Logs: Enable Artisan logging to trace command execution:
    Artisan::call('optimize:clear', ['--verbose' => true]);
    
  • Livewire Events: Verify event dispatching with:
    $this->dispatch('clearCacheIncrement')->to(\CmsMulti\FilamentClearCache\Http\Livewire\ClearCache::class);
    
    Check browser console for errors (e.g., Uncaught Error: Livewire event not found).

Extension Points

  1. Custom Styling:

    • Override Blade templates in resources/views/vendor/filament-clear-cache.
    • Example: Modify the button icon or tooltip.
  2. Pre/Post Actions:

    • Hook into the clearance process via service provider:
      FilamentClearCache::extend(function ($plugin) {
          $plugin->beforeClear(function () {
              // Pre-clear logic (e.g., log event)
          });
      });
      
  3. Multi-Tenancy:

    • Clear cache per tenant by extending the plugin’s handle() method:
      FilamentClearCachePlugin::make()
          ->handle(function () {
              Tenant::current()->clearCache();
          });
      

Configuration Quirks

  • Published Config: Publish with:

    php artisan vendor:publish --provider="CmsMulti\FilamentClearCache\FilamentClearCacheServiceProvider"
    

    Key options:

    • visible: Toggle button visibility (default: true).
    • commands: Array of custom commands to include.
    • session_key: Customize the session key for cache counts.
  • Session Key: If using changes_count, ensure the session driver is configured (e.g., file, database).

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.
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony
spatie/flare-daemon-runtime