Laravel 5.4 - php artisan cache:clear does not clear cache files when using 'file' cache driver

Laravel 5.4 - php artisan cache:clear does not clear cache files when using 'file' cache driver

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Laravel 5.4 Cache: Clear Does Not Clear Files When Using 'file' Driver

In a specific configuration within Laravel 5.4, running php artisan cache:clear can produce a deceptive success message while leaving behind hundreds of kilobytes of cached data. This scenario typically arises when the .env file sets CACHE_DRIVER=file and QUEUE_DRIVER=sync. The command reports "Cache cleared successfully," yet files persist in the storage/framework/cache directory. Understanding why this discrepancy exists requires looking at how Laravel manages cache expiration versus manual clearing, and how the queue restart mechanism interacts with a missing cache directory.

The core issue lies in the distinction between invalidating specific cache entries and wiping the entire storage directory. When you execute cache:clear, Laravel iterates through its configured driver to invalidate keys. For file-based caching, this involves deleting files that match known cache IDs. However, if your application has generated unique cache files for keys that have since been forgotten or if the internal index tracking is out of sync with the physical filesystem, those orphaned files remain untouched by the artisan command. The driver thinks it has cleared its state because it has reported success for the keys it knows about, but it does not perform a recursive rm -rf on the entire storage/framework/cache tree.

Attempting to manually delete these files using rm -rf * from within storage/framework/cache is technically feasible but risky in a production environment. While the file driver relies on the presence of these directories to store data, deleting them manually breaks the abstraction layer. When you subsequently run php artisan queue:restart, you encounter the specific error [ErrorException] file_put_contents(.../storage/framework/cache/ee/2f/...) failed to open stream: No such file or directory.

This error occurs because Laravel's queue worker initialization logic attempts to ensure the cache directory structure exists before writing any job metadata or state. If the manual rm -rf command removed the subdirectories (like storage/framework/cache/ee/2f/), the filesystem is left in an inconsistent state where the parent directory exists but the specific paths required for the queue worker are gone. The artisan command expects these directories to be present to initialize the cache driver correctly.

To safely resolve this without breaking future operations, you must recreate the missing directory structure before attempting to restart the queue. Simply running php artisan queue:restart is sufficient; it handles the directory creation automatically. However, if you manually deleted files, you should ensure the directories exist by running:

mkdir -p storage/framework/cache

Regarding the 236K of orphaned cache files remaining after cache:clear, there is no built-in "purge all" command for the file driver in Laravel 5.4 that guarantees a full filesystem wipe while maintaining internal consistency. The safest approach to clean up these specific orphaned files without triggering queue errors is to clear them manually after ensuring the directory structure is intact, or simply accept that they will be overwritten once new cache keys are generated by the application.

It is worth noting that if your QUEUE_DRIVER is set to sync, restarting the queue worker via php artisan queue:restart might be unnecessary unless you are specifically reloading a failed worker process. In many cases, skipping this command entirely resolves the error because the sync driver does not require a persistent background worker to manage state in the same way as Redis or database queues. If the application logic relies on the cache for job persistence (which is rare with sync), ensuring the directory structure exists is the critical step. For more robust cache management strategies, especially when dealing with file drivers and production environments, reviewing how your caching layer interacts with deployment scripts can prevent these state mismatches.

Our network