Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Clear Expired Cache File Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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.md
  • The package’s command class under vendor/arifhp86/laravel-clear-expired-cache-file/src
  • php artisan list | grep cache to confirm the exact command name in your installed version

Run 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.

Implementation Patterns

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:

  • Run daily for normal apps; hourly if you use many short-TTL file cache entries.
  • Use withoutOverlapping() to avoid concurrent scans on large cache directories.
  • Use runInBackground() if the cache directory is large and the scan may take time.
  • Use 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.
  • Log command output and alert on failures so silent permission problems do not go unnoticed.
  • Keep this separate from php artisan cache:clear. Use cache:clear for deliberate full invalidation; use this package for routine expired-file hygiene.
  • In local/staging, run it manually after changing cache TTLs or before disk-usage checks.

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');

Gotchas and Tips

  • This is for Laravel’s file cache only. It does not clean Redis, database, Memcached, DynamoDB, or other cache stores.
  • It removes expired entries; it does not invalidate valid entries. Use cache:forget() or cache:clear when you need explicit invalidation.
  • Verify the command targets the configured file cache path. If you changed cache.stores.file.path away from the default, test in staging; small packages sometimes assume the standard storage/framework/cache/data location.
  • Run the scheduler as the same user that owns the app’s storage files—typically www-data, nginx, or the deploy user. Do not run cleanup as root and leave root-owned cache files behind.
  • Cache file expiry is stored using Laravel’s internal file-cache format. Re-test after major Laravel upgrades, even though the package had a recent release.
  • Large cache directories make filesystem scans slow. Schedule off-peak, use withoutOverlapping(), and monitor runtime.
  • Avoid running this simultaneously with cache:clear, deploy scripts that remove the cache directory, or manual rm -rf storage/framework/cache/data.
  • If the command is not found after installation, run composer dump-autoload, php artisan package:discover, and clear cached config with php artisan config:clear.
  • This package is not a substitute for cache architecture. If file cache churn is consistently high, tune TTLs or move hot cache to Redis rather than relying on cleanup alone.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
ignibyte/aic-framework
glavweb/data-schema-bundle
glavweb/datagrid-bundle
tacticmedia/scim-server
uni-method/frame
neika-ai/sdk
adachsoft/php-code-style
pharaonic/laravel-notification-dependencies
beautinow/translug
dev-brainiac/bot-cloaked
octoberrain/html
octoberrain/extension
octoberrain/exception
octoberrain/contracts
adachsoft/api-version-bundle
cgv/localized-resource
noith/settings
kda/laravel-package
kda/filament-dynamic-navigation
bypersoft/signbox