PHP code example of arifhp86 / laravel-clear-expired-cache-file

1. Go to this page and download the library: Download arifhp86/laravel-clear-expired-cache-file library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

arifhp86 / laravel-clear-expired-cache-file example snippets


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

// 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
    //...
});

// 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
    //...
});
bash
php artisan cache:clear-expired
bash
php artisan cache:clear-expired --dry-run
bash
php artisan cache:clear-expired --disable-directory-delete