*/ public function labels(int $companyId): array { return $this->remember($companyId, 'label'); } /** @return list */ public function shops(int $companyId): array { return $this->remember($companyId, 'shop_name'); } public function warm(int $companyId): void { $this->labels($companyId); $this->shops($companyId); } public function forget(int $companyId): void { Cache::forget($this->key($companyId, 'label')); Cache::forget($this->key($companyId, 'shop_name')); } /** @return list */ private function remember(int $companyId, string $column): array { $key = $this->key($companyId, $column); $cached = Cache::get($key); if (is_array($cached)) { return $cached; } $values = JstOrderLabel::query() ->where('company_id', $companyId) ->whereNotNull($column) ->where($column, '<>', '') ->distinct() ->orderBy($column) ->limit(self::LIMIT) ->pluck($column) ->all(); Cache::put($key, $values, now()->addHours(self::TTL_HOURS)); return $values; } private function key(int $companyId, string $column): string { return "jst-order-labels:options:v1:{$companyId}:{$column}"; } }