Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
markvaneijk committed Apr 12, 2024
1 parent 362c854 commit 741124f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
21 changes: 11 additions & 10 deletions src/CachesValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\PendingDispatch;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\Cache;
use Illuminate\View\View;
use ReflectionClass;
Expand Down Expand Up @@ -48,17 +49,17 @@ trait CachesValue
*
* @internal You shouldn't call this yourself.
*/
final public function handle($event = null): void
final public function handle($parameters): void
{
[$driver, $ident] = self::store();

/** @phpstan-ignore-next-line */
if (null === $value = $this->{self::getUpdateMethodString()}($event)) {
return;
if(is_subclass_of(static::class, CachedComponent::class)) {
$value = Blade::renderComponent($this);
}

if (is_a($value, View::class)) {
$value = (string) $value;
/** @phpstan-ignore-next-line */
if (null === $value = $this->{self::getUpdateMethodString()}()) {
return;
}

Cache::driver($driver)->forever($ident, $value);
Expand All @@ -67,12 +68,12 @@ final public function handle($event = null): void
/**
* Manually force a static cache to update.
*/
final public static function update(): ?PendingDispatch
final public static function update($parameters = []): ?PendingDispatch
{
$instance = app()->make(static::class);
$instance = app()->make(static::class, $parameters);

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

return null;
}
Expand Down Expand Up @@ -122,7 +123,7 @@ final protected function value($default = null): mixed
public static function schedule($callback)
{
if (! is_a(static::class, Scheduled::class, true)) {
throw new \Exception('Can not schedule a cacher that does not implement the ['.Scheduled::class.'] interface');
throw new \Exception('Cannot schedule a cacher that does not implement the ['.Scheduled::class.'] interface');
}

$reflection = new ReflectionClass(static::class);
Expand Down
2 changes: 1 addition & 1 deletion src/PermanentCacheServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function bootingPackage()
$this->callAfterResolving(Schedule::class, fn (Schedule $schedule) => collect(Facades\PermanentCache::configuredCaches())
->filter(fn ($parameters, $cacherClass) => is_a($cacherClass, Scheduled::class, true))
->map(fn ($parameters, $cacherClass) => $this->app->make($cacherClass, $parameters))
->each(fn (Scheduled $cacherClass) => $cacherClass->schedule($schedule->job($cacherClass)))
->each(fn (Scheduled $instance) => $instance->schedule($schedule->job($instance)))
);
}
}

0 comments on commit 741124f

Please sign in to comment.