getCacheKey($departmentIds, $startDate, $endDate); if (isset($this->cache[$cacheKey])) { return $this->cache[$cacheKey]; } try { $result = $this->calculate($departmentIds, $startDate, $endDate); $this->cache[$cacheKey] = $result; return $result; } catch (\Exception $e) { Log::error("Error in " . static::class . ": " . $e->getMessage()); return array_fill_keys($departmentIds, 0); } } protected function getCacheKey(array $departmentIds, string $startDate, string $endDate): string { return static::class . '_' . md5(implode(',', $departmentIds) . $startDate . $endDate); } public function clearCache(): void { $this->cache = []; } }