PHPackages                             arifhp86/laravel-clear-expired-cache-file - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. arifhp86/laravel-clear-expired-cache-file

ActiveLibrary[Caching](/categories/caching)

arifhp86/laravel-clear-expired-cache-file
=========================================

Remove laravel expired cache file/folder

v1.0.4(1y ago)36140.7k↓40.8%14MITPHPPHP ^7.0|^8.0

Since May 2Pushed 1y ago1 watchersCompare

[ Source](https://github.com/arifhp86/laravel-clear-expired-cache-file)[ Packagist](https://packagist.org/packages/arifhp86/laravel-clear-expired-cache-file)[ RSS](/packages/arifhp86-laravel-clear-expired-cache-file/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (10)Dependencies (2)Versions (16)Used By (0)

Clear Expired Cache Files
=========================

[](#clear-expired-cache-files)

[![Latest Stable Version](https://camo.githubusercontent.com/8e992917b48c460fd23bf518a8e1d46b93158bf68603356c4715cdae39c860e2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f61726966687038362f6c61726176656c2d636c6561722d657870697265642d63616368652d66696c652e7376673f7374796c653d666c61742d737175617265)](https://github.com/arifhp86/laravel-clear-expired-cache-file/releases)[![MIT Licensed](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Total Downloads](https://camo.githubusercontent.com/cfe2a52c2c92917925c95c7814ab0cb6284bbd3c940694ca1ca6cd16ff40ab2d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f61726966687038362f6c61726176656c2d636c6561722d657870697265642d63616368652d66696c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/arifhp86/laravel-clear-expired-cache-file)

When you use the `file` cache driver, you may have noticed that the cache files are never deleted automatically. They are overwritten when the cache is refreshed which is good, but if there is some randomness in you cache keys, or for some other reason some of your cache files are never touched again, they will stay on your server forever. This package helps you to get rid of these lingering files.

This package only adds one artisan command: `php artisan cache:clear-expired` and it will delete all cache files that has already been expired.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require arifhp86/laravel-clear-expired-cache-file
```

Usage
-----

[](#usage)

Run the following command

```
php artisan cache:clear-expired
```

### Run on schedule

[](#run-on-schedule)

You can also schedule the command to run automatically. For example, if you want to run the command every day at 1 AM, you can add the following to your `app/Console/Kernel.php` file:

```
protected function schedule(Schedule $schedule)
{
    $schedule->command('cache:clear-expired')->dailyAt('01:00');
}
```

### Dry run

[](#dry-run)

You can run the command in dry run mode. In this mode, the command will not delete any files. It will only show you the files that will be deleted if you run the command without the `--dry-run` option.

```
php artisan cache:clear-expired --dry-run
```

### Disable directory deletion

[](#disable-directory-deletion)

By default, the command will delete all empty directories after deleting the expired files. You can disable this behavior by using the `--disable-directory-delete` option.

```
php artisan cache:clear-expired --disable-directory-delete
```

### Events

[](#events)

The command triggers three events:

- `Arifhp86\ClearExpiredCacheFile\Events\GarbageCollectionStarting`: Before the command runs.
- `Arifhp86\ClearExpiredCacheFile\Events\GarbageCollectionEnded`: After the command runs.
- `Arifhp86\ClearExpiredCacheFile\Events\GarbageCollectionFailed`: If the command fails.

You can use these events to run your own code before or after the command runs.

#### Send email notification after the command runs

[](#send-email-notification-after-the-command-runs)

```
// app/Providers/EventServiceProvider.php boot method

use Arifhp86\ClearExpiredCacheFile\Events\GarbageCollectionEnded;

Event::listen(function (GarbageCollectionEnded $event) {
    $timeTaken = $event->time; // in seconds
    $memory = $event->memory; // in bytes
    $numberOfFilesDeleted = $event->expiredFiles->getCount();
    $diskCleared = $event->expiredFiles->getFormattedSize();
    $remainingFiles = $event->activeFiles->getCount();
    $remainingDisk = $event->activeFiles->getFormattedSize();
    $numberOfDeletedDirectories = $event->deletedDirectories;

    // Send email notification
    //...
});
```

#### Send email notification if the command fails

[](#send-email-notification-if-the-command-fails)

```
// app/Providers/EventServiceProvider.php boot method

use Arifhp86\ClearExpiredCacheFile\Events\GarbageCollectionFailed;

Event::listen(function (GarbageCollectionFailed $event) {
    $exception = $event->exception;
    $message = $exception->getMessage();
    $stackTrace = $exception->getTraceAsString();

    // Send email notification
    //...
});
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Arifur Rahman](https://github.com/arifhp86)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

48

—

FairBetter than 93% of packages

Maintenance39

Infrequent updates — may be unmaintained

Popularity46

Moderate usage in the ecosystem

Community17

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 75% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~161 days

Recently: every ~70 days

Total

14

Last Release

524d ago

Major Versions

v0.0.6 → v1.0.02023-10-01

v1.0.0 → 2.x-dev2023-10-08

PHP version history (3 changes)v0.0.1PHP &gt;=5.4.0

v1.0.0PHP ^7.0|^8.0

2.x-devPHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/04b67ca4891c56840b5243abefee0d3f630bab0c6742b6311453e3a7da1b04fa?d=identicon)[arifhp86](/maintainers/arifhp86)

---

Top Contributors

[![arifhp86](https://avatars.githubusercontent.com/u/11217843?v=4)](https://github.com/arifhp86 "arifhp86 (18 commits)")[![saulposel](https://avatars.githubusercontent.com/u/1250594?v=4)](https://github.com/saulposel "saulposel (2 commits)")[![attogram](https://avatars.githubusercontent.com/u/8653063?v=4)](https://github.com/attogram "attogram (1 commits)")[![barry-pederson](https://avatars.githubusercontent.com/u/128503581?v=4)](https://github.com/barry-pederson "barry-pederson (1 commits)")[![jmdz](https://avatars.githubusercontent.com/u/1752126?v=4)](https://github.com/jmdz "jmdz (1 commits)")[![zaxxo-dkraemer](https://avatars.githubusercontent.com/u/122027358?v=4)](https://github.com/zaxxo-dkraemer "zaxxo-dkraemer (1 commits)")

---

Tags

laravelcacheclearexpired

### Embed Badge

![Health badge](/badges/arifhp86-laravel-clear-expired-cache-file/health.svg)

```
[![Health](https://phpackages.com/badges/arifhp86-laravel-clear-expired-cache-file/health.svg)](https://phpackages.com/packages/arifhp86-laravel-clear-expired-cache-file)
```

###  Alternatives

[statamic/cms

The Statamic CMS Core Package

4.8k3.6M987](/packages/statamic-cms)[swayok/alternative-laravel-cache

Replacements for Laravel's redis and file cache stores that properly implement tagging idea. Powered by cache pool implementations provided by http://www.php-cache.com/

202583.7k8](/packages/swayok-alternative-laravel-cache)[vectorial1024/laravel-cache-evict

Efficiently remove expired Laravel file/database cache data

5917.4k](/packages/vectorial1024-laravel-cache-evict)[api-platform/laravel

API Platform support for Laravel

58171.5k14](/packages/api-platform-laravel)[byerikas/cache-tags

Allows for Redis/Valkey cache flushing multiple tagged items by a single tag.

1420.4k](/packages/byerikas-cache-tags)[ecotone/laravel

Ecotone for Laravel — CQRS, Event Sourcing, Sagas, Durable Workflows, and Outbox on top of Laravel Queue, via PHP attributes.

21318.6k3](/packages/ecotone-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
