Skip to content

Commit

Permalink
add manual dispatching for static caches
Browse files Browse the repository at this point in the history
  • Loading branch information
david-d-h committed Dec 12, 2023
1 parent cd8c63c commit b771887
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/Cached.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Vormkracht10\PermanentCache;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Cache;
use ReflectionClass;

Expand All @@ -14,7 +14,7 @@
*/
abstract class Cached
{
use InteractsWithQueue, Queueable;
use Queueable;

/**
* The driver and identifier that will be used to cache this value.
Expand Down Expand Up @@ -58,6 +58,23 @@ final public function handle($event = null): void
);
}

/**
* Manually force a static cache to update.
*
* @return void
*/
final public static function update(): void
{
$instance = app()->make(static::class);

if (! is_a(static::class, ShouldQueue::class, true)) {
$instance->handle();
return;
}

dispatch($instance);
}

/**
* Get the cached value this cacher provides.
*/
Expand Down

0 comments on commit b771887

Please sign in to comment.