Cache integration API reads and refresh them on a schedule
Deploy HickLab3D Dashboard / Deploy to production (push) Successful in 28s
Deploy HickLab3D Dashboard / Deploy to production (push) Successful in 28s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
8bee8d42c7
commit
2fe4fbd91e
@@ -7,7 +7,7 @@ use RuntimeException;
|
||||
|
||||
class DryerClient
|
||||
{
|
||||
public function __construct(private IntegrationSettings $settings) {}
|
||||
public function __construct(private IntegrationSettings $settings, private IntegrationCache $cache) {}
|
||||
|
||||
public function configured(): bool
|
||||
{
|
||||
@@ -45,14 +45,14 @@ class DryerClient
|
||||
|
||||
public function status(): array
|
||||
{
|
||||
return Http::withHeaders(['X-API-Key' => $this->apiKey()])->acceptJson()
|
||||
->connectTimeout(3)->timeout(7)->get($this->url('status'))->throw()->json() ?? [];
|
||||
return $this->cache->remember('dryer.status', 20, fn (): array => Http::withHeaders(['X-API-Key' => $this->apiKey()])->acceptJson()
|
||||
->connectTimeout(3)->timeout(7)->get($this->url('status'))->throw()->json() ?? []);
|
||||
}
|
||||
|
||||
public function history(): array
|
||||
{
|
||||
return Http::withHeaders(['X-API-Key' => $this->apiKey()])->acceptJson()
|
||||
->connectTimeout(3)->timeout(7)->get($this->url('history'), ['limit' => 60])->throw()->json() ?? [];
|
||||
return $this->cache->remember('dryer.history', 120, fn (): array => Http::withHeaders(['X-API-Key' => $this->apiKey()])->acceptJson()
|
||||
->connectTimeout(3)->timeout(7)->get($this->url('history'), ['limit' => 60])->throw()->json() ?? []);
|
||||
}
|
||||
|
||||
public function start(string $profile, int $targetTemperature, int $dryingTime): array
|
||||
@@ -74,6 +74,9 @@ class DryerClient
|
||||
|
||||
private function command(string $path, array $payload = []): array
|
||||
{
|
||||
$this->cache->forget('dryer.status');
|
||||
$this->cache->forget('dryer.history');
|
||||
|
||||
return Http::withHeaders(['X-API-Key' => $this->apiKey()])->acceptJson()
|
||||
->connectTimeout(3)->timeout(7)->post($this->url($path), [
|
||||
'requestId' => 'dashboard-'.bin2hex(random_bytes(12)), ...$payload,
|
||||
|
||||
Reference in New Issue
Block a user