Skip to content

Commit

Permalink
Add a command to flush the whole cache
Browse files Browse the repository at this point in the history
  • Loading branch information
antonioribeiro committed Oct 21, 2022
1 parent 6907d43 commit 1fe4cc5
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

All notable changes to `CDN` will be documented in this file.

## 1.3.XX - 2022-10-XX
### Added
- Full cache invalidation command: php artisan edge-flush:invalidate-all


## 1.3.10 - 2022-09-26
### Fixed
- Correctly setting was_purged_at update SQL
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ Akamai has a 128 bytes limit for the tag list, so if one page is impacted by lot
edge-cache-tag: app-production-7e0ae085d699003a64e5fa7b75daae3d78ace842
```

## Invalidating the full cache from the command line

In case you need to invalidate the whole CDN cache locally or on a deployment routing, you can:

```
php artisan edge-flush:invalidate-all
```

## Changelog

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
Expand Down
43 changes: 43 additions & 0 deletions src/Console/Commands/InvalidateAll.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace A17\EdgeFlush\Console\Commands;

use A17\EdgeFlush\EdgeFlush;
use Illuminate\Console\Command;

class InvalidateAll extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'edge-flush:invalidate-all';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Invalidate all pages from CDN cache';

/**
* Create a new command instance.
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*/
public function handle(): int
{
EdgeFlush::tags()->invalidateAll();

$this->info('An invalidation was created.');

return 0;
}
}
8 changes: 8 additions & 0 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use A17\EdgeFlush\Services\BaseService;
use A17\EdgeFlush\Services\CacheControl;
use A17\EdgeFlush\EdgeFlush as EdgeFlushFacade;
use A17\EdgeFlush\Console\Commands\InvalidateAll;
use A17\EdgeFlush\Exceptions\EdgeFlush as EdgeFlushxception;
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;

Expand All @@ -16,6 +17,8 @@ public function boot(): void
$this->publishConfig();

$this->loadMigrationsFrom(__DIR__ . '/../database/migrations');

$this->loadCommands();
}

public function register(): void
Expand Down Expand Up @@ -70,4 +73,9 @@ public function configureContainer(): void
return EdgeFlushFacade::cacheControl();
});
}

public function loadCommands(): void
{
$this->commands([InvalidateAll::class]);
}
}

0 comments on commit 1fe4cc5

Please sign in to comment.