<?php
namespace App\Service;
use App\Repository\ProfileRepository;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Contracts\Cache\ItemInterface;
class LocationsProfileCounters
{
const CACHE_ITEM_POOL_KEY = 'menu.city_stations';
const CACHE_ITEM_POOL_KEY_BY_STATIONS = 'menu.location_block.city_stations';
const CACHE_ITEM_POOL_KEY_BY_DISTRICTS = 'menu.location_block.city_districts';
const CACHE_ITEM_POOL_KEY_BY_COUNTIES = 'menu.location_block.city_counties';
public function __construct(
private ProfileRepository $profileRepository,
private CacheItemPoolInterface $ctrStatCache,
) {}
public function getCountByStations(): array
{
return $this->ctrStatCache->get(self::CACHE_ITEM_POOL_KEY_BY_STATIONS, function (ItemInterface $item): array {
return $this->profileRepository->countByStations();
});
}
public function getCountByDistricts(): array
{
return $this->ctrStatCache->get(self::CACHE_ITEM_POOL_KEY_BY_DISTRICTS, function (ItemInterface $item): array {
return $this->profileRepository->countByDistricts();
});
}
public function getCountByCounties(): array
{
return $this->ctrStatCache->get(self::CACHE_ITEM_POOL_KEY_BY_COUNTIES, function (ItemInterface $item): array {
return $this->profileRepository->countByCounties();
});
}
}