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

Remove laravel expired cache file/folder

Frequently asked questions about Laravel Clear Expired Cache File
How do I install arifhp86/laravel-clear-expired-cache-file?
Install it with composer require arifhp86/laravel-clear-expired-cache-file on a Laravel application that uses the file cache driver. The package registers its artisan command through Laravel package auto-discovery, so manual service provider registration is normally unnecessary. There are no database migrations and config publication is likely optional, so setup is essentially just the Composer install. Run the command against a staging cache directory first to confirm behavior on your Laravel version.
What exactly does this package delete from storage/framework/cache?
It walks Laravel's file cache directory and removes cache entries whose TTL has elapsed, filling the reclamation gap left by the file driver. Laravel nests entries two levels deep under storage/framework/cache/data (for example data/ab/cd/hash), so a correct implementation deletes only leaf files and leaves the directory structure intact. It is not a replacement for cache:clear, which wipes the whole store; this only targets abandoned entries. Confirm the traversal depth in the source before running it against production storage.
Does laravel-clear-expired-cache-file support Laravel 11 and Laravel 12?
The January 2025 release predates Laravel 12, so treat 12.x support as unverified until you read the version constraints in the package's composer.json. Laravel 11 is the more likely supported target given the release date, but confirm both the framework constraint and the PHP constraint (8.3 and 8.4) before committing. If the constraint is too narrow, Composer will refuse to install it on your app, which is a safe failure. Check the repository's composer.json rather than relying on a README badge.
How do I run the expired cache cleanup automatically with the Laravel scheduler?
Add the package's artisan command to your scheduler in routes/console.php or app/Console/Kernel.php, typically hourly or daily depending on key cardinality. Guard the schedule entry on the configured cache driver being file, so the job does not churn on Redis, Memcached, database, or DynamoDB stores where it does nothing. Consider withoutOverlapping() to prevent a second run starting while a large directory sweep is still in progress. Verify the exact command signature in the source before wiring it up.
Does this package work if my app uses Redis or the database cache driver?
No. It operates on the filesystem and only makes sense when the cache store is file, which was the Laravel default through version 10 and remains common in local and single-server setups. On Redis, Memcached, DynamoDB, or database-backed stores it is a no-op at best. The clean approach is to register the schedule entry conditionally on the actual cache driver rather than assuming file storage everywhere.
How is this different from php artisan cache:clear?
cache:clear wipes the entire cache store, which is what you want at deploy time for correctness reasons like stale config or route caches. This package only reclaims entries that have already expired, so valid entries survive the sweep and you avoid a cold-cache stampede against the database. The two are complementary: cache:clear handles correctness, this handles accumulation. Do not schedule cache:clear on a timer in production for that reason.
How does it determine whether a cache file is expired?
This is the single most important thing to verify in the source. Laravel stores the expiration timestamp inside the serialized cache payload, so a correct implementation deserializes each file and reads expiresAt. A naive implementation uses filemtime() plus a fixed TTL or a flat age threshold, which will delete still-valid entries and can trigger a cache stampede. Read the deletion logic before pointing it at a production cache directory.
Is it safe to run against a production cache directory?
Deleting a file mid-read produces a cache miss, not corruption, so the failure mode is a degraded hit rate rather than broken data. The real risks are path traversal, where a recursive delete rooted one level too high can take out sibling directories under storage/framework/cache, and IO pressure from overlapping cron runs on a large directory. Test on staging first, confirm whether a dry-run option exists, and pin the version you audited. If there is no dry-run flag, snapshot the directory or point the command at a copy before the first production run.
Should I use this package or write my own artisan command?
The core logic is plausibly around 80 lines: recurse the two-level hash directories, deserialize each payload, compare expiresAt to the current time, and unlink the leaf file. Building it in-house gives you full control over path resolution, locking, and output, which matters if your cache path is customized. Buying it is cheaper only if a pinned, audited copy is genuinely maintained. Given the package's maintenance profile, an internal command is a legitimate alternative if your team will actually own it.
Is the package actively maintained and safe from a supply chain perspective?
The repository shows a single maintainer and a small star count with no visible security review, so treat it as a small utility rather than an audited dependency. Run composer audit, pin an exact version, and consider vendoring the source or forking it so an upstream change cannot silently alter deletion behavior. A package that deletes files deserves more scrutiny than one that only reads them.
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.
shitoudev/permissionmanager
johannesclimacus/laravel-tui
hocvt/seotools
vitalybaev/sypexgeo
amphibee/themosis-ignition
gito-me/fast-excel
frankyso/laravel-ipaymu
geolize-studio/laravel-chile
boomerangui/chat
jinas/dhivatar
store-doc/laravel-storage-driver
plus-it/laravel-translation-manager
diephp/perhaps
diephp/telegraph
osmaviation/spreadsheet
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console