Add a separate pool to keep iss_data

This commit is contained in:
Krzysztof Płaczek
2024-10-21 09:02:25 +02:00
parent d44091fe6e
commit e935820570
2 changed files with 10 additions and 7 deletions

View File

@@ -15,5 +15,6 @@ framework:
#app: cache.adapter.apcu
# Namespaced pools use the above "app" backend by default
#pools:
#my.dedicated.cache: null
pools:
iss_location:
default_lifetime: 120

View File

@@ -6,6 +6,7 @@ use App\Repository\StarshipRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
class MainController extends AbstractController
@@ -13,13 +14,14 @@ class MainController extends AbstractController
#[Route('/', name: 'app_homepage')]
public function homepage(
HttpClientInterface $client,
StarshipRepository $repository): Response
{
StarshipRepository $repository,
CacheInterface $issLocation,
): Response {
$starships = $repository->findAll();
$starship = $starships[array_rand($starships)];
$response = $client->request('GET', 'https://api.wheretheiss.at/v1/satellites/25544');
$issData = $response->toArray();
$issData = $issLocation->get('iss_data', function () use ($client): array {
return $client->request('GET', 'https://api.wheretheiss.at/v1/satellites/25544')->toArray();
});
return $this->render('main/homepage.html.twig', ['ships' => $starships, 'myShip' => $starship, 'issData' => $issData]);
}