src/Service/LocationsProfileCounters.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Service;
  3. use App\Repository\ProfileRepository;
  4. use Psr\Cache\CacheItemPoolInterface;
  5. use Symfony\Contracts\Cache\ItemInterface;
  6. class LocationsProfileCounters
  7. {
  8.     const CACHE_ITEM_POOL_KEY 'menu.city_stations';
  9.     const CACHE_ITEM_POOL_KEY_BY_STATIONS 'menu.location_block.city_stations';
  10.     const CACHE_ITEM_POOL_KEY_BY_DISTRICTS 'menu.location_block.city_districts';
  11.     const CACHE_ITEM_POOL_KEY_BY_COUNTIES 'menu.location_block.city_counties';
  12.     public function __construct(
  13.         private ProfileRepository $profileRepository,
  14.         private CacheItemPoolInterface $ctrStatCache,
  15.     ) {}
  16.     public function getCountByStations(): array
  17.     {
  18.         return $this->ctrStatCache->get(self::CACHE_ITEM_POOL_KEY_BY_STATIONS, function (ItemInterface $item): array {
  19.             return $this->profileRepository->countByStations();
  20.         });
  21.     }
  22.     public function getCountByDistricts(): array
  23.     {
  24.         return $this->ctrStatCache->get(self::CACHE_ITEM_POOL_KEY_BY_DISTRICTS, function (ItemInterface $item): array {
  25.             return $this->profileRepository->countByDistricts();
  26.         });
  27.     }
  28.     public function getCountByCounties(): array
  29.     {
  30.         return $this->ctrStatCache->get(self::CACHE_ITEM_POOL_KEY_BY_COUNTIES, function (ItemInterface $item): array {
  31.             return $this->profileRepository->countByCounties();
  32.         });
  33.     }
  34. }