我已经在应用程序和缓存驱动程序中实现了缓存的查询是CCD_ 1。但我想在一定时间后清除所有缓存的查询。
如何使用CLI或在控制器中执行此操作?
php artisan cache:clear
控制器中:
Artisan::call('cache:clear');
您可以使用此artisan命令从您的laravel项目中清除缓存:
//---Remove Routes Cache
php artisan route:clear;
php artisan route:cache
//---Flush the application cache
php artisan cache:clear;
//---Remove the configuration cache file
php artisan config:cache;
php artisan config:clear;
//---Clearing View Cache
php artisan view:clear;
php artisan view:cache;
要了解有关缓存的更多信息,请访问以下URL:
https://dev.to/kenfai/laravel-artisan-cache-commands-explained-41e1#:~:text=要%20clear%20your%20application%20cache,cache%3clear%20application%20cache%20cleared!
Artisan::call(['cache:clear']);
将运行命令CCD_ 2。如果您希望它自动完成,您可以在调度程序中调用该命令。
app/Console/Kernel.php
<?php
namespace AppConsole;
use IlluminateConsoleSchedulingSchedule;
use IlluminateFoundationConsoleKernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
//
];
/**
* Define the application's command schedule.
*
* @param IlluminateConsoleSchedulingSchedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('cache:clear')->weekly();
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
如果您将此条目添加到crontab中,这将自动运行。
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
关于运行调度程序的更多信息