mitydigital/statamic-scheduled-cache-invalidator
A Statamic addon for scheduling cache invalidation, helping you automatically refresh stale content on a timetable. Define invalidation rules and timings to keep cached pages fast and up to date without manual clears.
Install via Composer: composer require mitydigital/statamic-scheduled-cache-invalidator. Publish the config and migrations: php artisan vendor:publish --tag="statamic-scheduled-cache-invalidator-config" and php artisan vendor:publish --tag="statamic-scheduled-cache-invalidator-migrations", then run php artisan migrate. Add the scheduler entry to app/Console/Kernel.php (or routes/console.php in Laravel 11+): $schedule->command('statamic:cache-invalidator:run')->everyMinute()->withoutOverlapping();. First use case: in the Statamic CP, add the “Scheduled Cache Invalidator” field to a collection or use the provided listing to schedule cache invalidation for an entry’s URL. Alternatively, create a record programmatically via the package’s Eloquent model (ScheduledCacheInvalidation) to schedule invalidation at a future timestamp.
ScheduledCacheInvalidation::create(['url' => $url, 'scheduled_at' => now()->addHour()]);. The model supports polymorphic relations (invalidatable_type, invalidatable_id) to tie invalidations to entries, terms, or assets.EntrySaved, TermSaved) and conditionally schedule invalidations, e.g., when a future publish date is set.url field contains the full domain (or use the package’s URL resolver) so that the correct site’s cache is cleared.onOneServer() and consider a dedicated queue.scheduled_at is stored in UTC by default; ensure APP_TIMEZONE is set correctly and that CP inputs are converted appropriately.composer update and re-run migrations if you have custom model overrides; no breaking changes expected.withoutOverlapping() to prevent concurrent runs, and ensure the scheduler is actually running (e.g., cron entry or schedule:work).model key) or override the command; publish the config to adjust table names, queue settings, or the invalidation strategy.Cache::shouldReceive('forget') or a fake cache driver in tests; the package’s command can be invoked directly in feature tests.How can I help you explore Laravel packages today?