Penambahn P1 Dev

This commit is contained in:
Ariyutta
2026-10-20 10:24:22 +07:00
parent 8418a63fc0
commit ee0e6deacc
43 changed files with 5406 additions and 44 deletions
+40
View File
@@ -0,0 +1,40 @@
<?php
namespace App\Services\P1Dev;
use Closure;
use Illuminate\Support\Facades\Cache;
class P1DataCache
{
public function key(string $kind, int|string $year, int|string $month, mixed $unit, string $employeeType): string
{
$unitKey = $unit === null || $unit === '' ? 'all' : (string) ((int) $unit === 0 ? 99 : (int) $unit);
return 'p1_snapshot_v1:'.(int) $year.':'.(int) $month.':'.$unitKey.':'.$kind.':'.$employeeType;
}
public function remember(string $kind, int|string $year, int|string $month, mixed $unit, string $employeeType, Closure $load): array
{
return Cache::rememberForever($this->key($kind, $year, $month, $unit, $employeeType), $load);
}
public function forget(int|string $year, int|string $month, mixed $unit): void
{
foreach (['', 'dosen', 'tendik', 'jtt', 'jtt-univ'] as $type) {
foreach (['main', 'selisih', 'perbandingan'] as $kind) {
Cache::forget($this->key($kind, $year, $month, $unit, $type));
}
}
}
public function refresh(int|string $year, int|string $month, mixed $unit, string $employeeType, Closure $main, Closure $selisih): void
{
// Keep the previous snapshot intact if an upstream request fails.
$mainData = $main();
$selisihData = $selisih();
$this->forget($year, $month, $unit);
Cache::forever($this->key('main', $year, $month, $unit, $employeeType), $mainData);
Cache::forever($this->key('selisih', $year, $month, $unit, $employeeType), $selisihData);
}
}