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

Product Decisions This Supports

  • Build vs. buy for cache hygiene: Laravel's 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.
  • Roadmap / infrastructure reliability: Useful as a scheduled job in deployments where 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.
  • Deployment and environment strategy: Informs whether file caching is acceptable for a given environment (shared hosting, single-server, low-traffic apps where Redis isn't provisioned) versus where it's a liability (multi-node, containerized with ephemeral disks, high key churn).
  • Operational runbook scope: Adds a concrete item to the maintenance checklist — schedule 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.
  • Dependency governance: A data point for the "minimum viable dependency" policy — whether the team accepts low-star, single-maintainer packages for non-critical paths. This is a low-blast-radius dependency (worst case: a cron job fails and disk fills more slowly), which makes it a reasonable candidate for a permissive policy.
  • Use cases that justify it: Long-lived VMs or bare-metal hosts, apps with high-cardinality cache keys, tenants with per-user cache namespacing, environments without Redis, and teams already running Laravel's scheduler who want a one-line addition.

When to Consider This Package

Adopt when all of the following hold:

  • The application uses the file cache driver in at least one long-lived environment (production VM, staging, on-prem).
  • Cache key cardinality is high or traffic is bursty enough that expired files measurably accumulate (check storage/framework/cache/data size over 30 days before deciding — this is the single most important validation step).
  • The team already runs schedule:run via cron or a supervisor, so adding a scheduled command is free.
  • Nobody wants to own the ~50 lines of glob-and-unlink logic, including its edge cases (nested sharding directories, race conditions with concurrent writes, filemtime vs. embedded expiry).
  • The blast radius is acceptable: a failure means stale files linger, not that the app breaks.

Look elsewhere or skip when:

  • Using Redis, Memcached, DynamoDB, or database cache — TTL is enforced by the store; this package does nothing for you.
  • Containerized/ephemeral filesystem deployments — the disk is discarded on every deploy; the problem doesn't exist.
  • You need more than expiry cleanup — e.g., size-capped eviction, LRU policies, or metrics. Laravel's cache API doesn't expose that, and this package doesn't either.
  • Strict dependency review process — 34 stars, single maintainer, and a last release in January 2025. Verify the source before adopting; the code is short enough to audit in fifteen minutes, which is exactly what I'd recommend doing rather than trusting the star count.
  • You want a supported, long-term dependency — this is a utility, not a platform. Fork it or vendor the command into app/Console/Commands and remove the supply-chain question entirely.
  • Alternative worth benchmarking: Laravel's built-in 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.

How to Pitch It (Stakeholders)

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.

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.
andydefer/laravel-notification
adachsoft/cli-process-tester
jhaskell13/laraflow
sebastienheyd/boilerplate-media-manager
ccast/tagixo-primix
pretendtrue/laravel-builder
sawmainek/laravel-scout-tntsearch-driver
tomshaw/laravel-calendar-table
dibakar/laravel-ownership
steadrun/laravel-monitor
labyrinthe/connect-laravel
elmogy/layan
drewdan/sentinel-client
dskripchenko/laravel-llm
fatryst/nuonuo
stevenay/myanfont
gmostafa/php-graphql-client
xeviant/paystack
snowsoft/faker
meditationsteps/blogetc