arifhp86/laravel-clear-expired-cache-file
A Laravel package that deletes expired cache files from your filesystem, keeping storage tidy and preventing stale cache buildup. Includes an artisan command and scheduler support for automatic cleanup of abandoned cache entries.
Install the package with Composer:
composer require arifhp86/laravel-clear-expired-cache-file
Confirm the app is using Laravel’s file cache store. In Laravel 11+ this is usually CACHE_STORE=file; in older versions it is CACHE_DRIVER=file. Check the configured path in config/cache.php under stores.file.path—normally storage/framework/cache/data.
Laravel package auto-discovery should register the service provider. No config is usually required for the default file cache. Look first at:
vendor/arifhp86/laravel-clear-expired-cache-file/README.mdvendor/arifhp86/laravel-clear-expired-cache-file/srcphp artisan list | grep cache to confirm the exact command name in your installed versionRun it once manually:
php artisan cache:clear-expired
The command scans the file cache, removes cache entries whose embedded expiry has passed, and cleans up resulting empty cache directories. The first practical use case is a production app using file cache where expired entries accumulate under storage/framework/cache/data and slowly consume disk.
Schedule the command instead of running it from application code. In Laravel 11+ routes/console.php:
use Illuminate\Support\Facades\Schedule;
Schedule::command('cache:clear-expired')
->daily()
->withoutOverlapping()
->appendOutputTo(storage_path('logs/cache-cleanup.log'));
In older Laravel versions, put the same call in app/Console/Kernel.php inside schedule().
Typical patterns:
withoutOverlapping() to avoid concurrent scans on large cache directories.runInBackground() if the cache directory is large and the scan may take time.onOneServer() only when all app servers share the same cache storage. If each server has its own local storage/framework/cache/data, let each server run its own cleanup.php artisan cache:clear. Use cache:clear for deliberate full invalidation; use this package for routine expired-file hygiene.A useful scheduler guard is to run it only in production and only when the file store is active:
Schedule::command('cache:clear-expired')
->daily()
->withoutOverlapping()
->environments(['production'])
->when(fn () => config('cache.default') === 'file');
cache:forget() or cache:clear when you need explicit invalidation.cache.stores.file.path away from the default, test in staging; small packages sometimes assume the standard storage/framework/cache/data location.www-data, nginx, or the deploy user. Do not run cleanup as root and leave root-owned cache files behind.withoutOverlapping(), and monitor runtime.cache:clear, deploy scripts that remove the cache directory, or manual rm -rf storage/framework/cache/data.composer dump-autoload, php artisan package:discover, and clear cached config with php artisan config:clear.How can I help you explore Laravel packages today?