Laravelのキャッシュ生成・削除系コマンドの違い一覧
キャッシュ生成や削除コマンドはいくつか用意されているがコマンドによっては複数種のキャッシュを操作したりしなかったりするのでまとめておく。
command | config | route | view | event | cache | compiled | description |
---|---|---|---|---|---|---|---|
config:cache | C | C | Create a cache file for faster configuration loading | ||||
config:clear | D | C | Remove the configuration cache file | ||||
route:cache | C | C | Create a route cache file for faster route registration | ||||
route:clear | D | C | Remove the route cache file | ||||
view:cache | C | C | Compile all of the application's Blade templates | ||||
view:clear | D | C | Clear all compiled view files | ||||
event:cache | C | C | Discover and cache the application's events and listeners | ||||
event:clear | D | C | Clear all cached events and listeners | ||||
cache:clear | D | C | Flush the application cache | ||||
cache:forget | D*1 | C | Remove an item from the cache | ||||
optimize | C | C | C | Cache the framework bootstrap files | |||
optimize:clear | D | D | D | D | D | Remove the cached bootstrap files | |
clear-compiled | D | Remove the compiled class file |
C: キャッシュ作成、 D: キャッシュ削除、 *1 指定されたキーのキャッシュのみを削除
基本的に xxx:cache ⇔ xxx:clear
が対になっており、作成コマンドは削除→作成の順番で実行される。
optimize
のみ操作が非対称な点に注意。
compiled
キャッシュはLaravelアクセス時に自動生成されるため、compiledキャッシュ削除コマンド以外では生成される。
デプロイ時は以下のコマンド実行で一通りのキャッシュを葬り去ることができる。
php artisan optimize:clear php artisan optimize php artisan view:cache php artisan event:cache // ジョブ機能を利用している場合のみ php artisan queue:flush
各キャッシュの生成されるファイル一覧
config
/bootstrap/cache/config.php
に各configがマージされた配列として保存される。
route
/bootstrap/cache/route.php
に各routeがマージされ、シリアライズされたデータとして保存される。
view:cache
\storage\framework\views
ディレクトリ内に各bladeファイルがphpにパースされたものが保存される。
また、ファイル名はsha1でハッシュ化される。
https://github.com/laravel/framework/blob/master/src/Illuminate/View/Compilers/Compiler.php#L51
event:cache
/bootstrap/cache/event.php
に各イベントがマージされた配列として保存される。
compiled
依存パッケージのパス、サービスプロバイダが配列として保存される。
/bootstrap/cache/packages.php
, /bootstrap/cache/services.php