Skip to content

Commit

Permalink
Add persist driver cache, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
marcheffels committed May 16, 2024
1 parent 5ce8348 commit 5504549
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/Concerns/Persist.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ protected function persistState(string $tableItem): void
return;
}

$jsonState = strval(json_encode($state));

match ($this->getPersistDriverConfig()) {
'session' => Session::put($this->getPersistKeyName(), strval(json_encode($state))),
'cache' => Cache::store($this->getPersistDriverStoreConfig())->put($this->getPersistKeyName(), strval(json_encode($state))),
default => Cookie::queue($this->getPersistKeyName(), strval(json_encode($state)), now()->addYears(5)->unix())
'session' => Session::put($this->getPersistKeyName(), $jsonState),
'cache' => Cache::store($this->getPersistDriverStoreConfig())->put($this->getPersistKeyName(), $jsonState),
default => Cookie::queue($this->getPersistKeyName(), $jsonState, now()->addYears(5)->unix())
};
}

Expand Down Expand Up @@ -109,16 +111,16 @@ private function getPersistDriverConfig(): string
{
$persistDriver = strval(config('livewire-powergrid.persist_driver', 'cookies'));

if (!in_array($persistDriver, ['session', 'cache', 'cookies',])) {
if (!in_array($persistDriver, ['session', 'cache', 'cookies'])) {
throw new Exception('Invalid persist driver');
}

return $persistDriver;
}

private function getPersistDriverStoreConfig(): ?string
private function getPersistDriverStoreConfig(): string
{
return config('livewire-powergrid.persist_driver_store');
return strval(config('livewire-powergrid.persist_driver_store'));
}

private function getPersistKeyName(): string
Expand Down

0 comments on commit 5504549

Please sign in to comment.