Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Maha_oueghlani's avatar

Clear cache automatically

There are any way to clear cache every day or every time interval automatically not manually ? no for clearing cache I run php artisan opimize in the server ( to clear all caches), but it's not parctice, also I defined a route to clear cache like this :

Route::get('/clear-cache', function() {
    $exitCode = Artisan::call('cache:clear');
});

but I don't know how to execute this route automatically

0 likes
7 replies
feralam's avatar

@Sinnbeck does not clear the cache tested in local development, but if I run the command manually it clears, what is the cause?


class Kernel extends ConsoleKernel
{
    protected function schedule(Schedule $schedule)
    {
        $schedule->command('cache:clear')->everyMinute();
    }

    protected function commands()
    {
        $this->load(__DIR__ . '/Commands');

        require base_path('routes/console.php');
    }
}
Snapey's avatar

@feralam it won't totally clear the cache if you have something in the same request cycle that writes to cache

I mean it might clear the cache but then set something in it

1 like

Please or to participate in this conversation.