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.
file cache driver stores each entry as a timestamped file and never garbage-collects expired entries on its own — TTL is checked on read, not enforced on disk. This package answers a small but real operational gap: "who deletes the dead files?" The decision is genuinely binary — adopt a 34-star MIT wrapper, or write the equivalent 40–80 line artisan command in-house. Neither is wrong; the question is whether the maintenance overhead of a third-party dependency is cheaper than owning ~1 file of code.CACHE_DRIVER=file and cache keys are highly variable (per-user, per-tenant, per-request fragments). Supports decisions like "do we need to move to Redis?" If disk pressure from expired cache files is enough of a recurring problem to warrant a cleanup command, that's a signal to evaluate Redis/Memcached — both of which enforce TTL natively and make this package unnecessary.cache:clear-expired (or the package's command) alongside queue:prune-failed, model:prune, log rotation, and session cleanup. Good for standardizing "housekeeping commands" across a fleet of Laravel apps.Adopt when all of the following hold:
file cache driver in at least one long-lived environment (production VM, staging, on-prem).storage/framework/cache/data size over 30 days before deciding — this is the single most important validation step).schedule:run via cron or a supervisor, so adding a scheduled command is free.filemtime vs. embedded expiry).Look elsewhere or skip when:
app/Console/Commands and remove the supply-chain question entirely.cache:clear (nukes everything — too blunt if you want to preserve warm entries) and php artisan cache:prune-stale-tags (tagged caches only). Neither replaces per-file expiry sweeping, which is why the gap exists.For executives (30 seconds): "Laravel's file-based cache never deletes expired entries — it just stops serving them. On apps that run on a single server without Redis, those files pile up and can quietly consume disk until something breaks. This is a small, free, MIT-licensed utility that adds one scheduled command to clean them up. It's a low-cost preventive measure, not a strategic investment, and it also gives us a data point on whether we should migrate that app to Redis."
For engineering (the actual case): "It's a thin artisan command that walks the file cache directory and removes entries past their expiry. We schedule it nightly via the existing scheduler — a two-line change. Risk is minimal: worst case the job no-ops or fails and disk fills at the current rate. Two caveats worth stating up front: (1) it's a 34-star, single-maintainer package, so I'd want us to read the source before merging — it's short enough that forking it into app/Console/Commands is a legitimate alternative and removes the dependency entirely; (2) if we're seeing meaningful disk growth from cache files, that's a symptom worth investigating, because Redis would solve this natively and give us better cache performance besides."
The honest framing: treat this as a stopgap or a convenience, not a solution. The right long-term answer for a growing app is a cache backend that enforces TTL itself. If the cleanup command is genuinely necessary in production, that's the argument for the Redis migration, and this package is what buys you time until that happens.
How can I help you explore Laravel packages today?