feat: removed caching of list view

This commit is contained in:
Björn Fromme
2025-01-25 15:25:34 +01:00
parent f9e7f28b6b
commit 289668bcbd
2 changed files with 9 additions and 28 deletions
+3 -5
View File
@@ -39,10 +39,9 @@ class EditController extends AbstractController
}
// Fetch original bookingData data via API and cache result for a short ttl
$cacheKeyList = sprintf('bpn_bookings_%s', sha1($bpnUser->getUserIdentifier()));
$cacheKeySingle = sprintf('bpn_booking_%d', $id);
$cacheKey = sprintf('bpn_booking_%d', $id);
try {
$bookingData = $this->cache->get($cacheKeySingle, function (ItemInterface $item) use ($bpnUser, $id) {
$bookingData = $this->cache->get($cacheKey, function (ItemInterface $item) use ($bpnUser, $id) {
$item->expiresAfter(300);
return $this->apiClient->getBooking($bpnUser->getEmail(), $bpnUser->getPassword(), $id);
@@ -90,8 +89,7 @@ class EditController extends AbstractController
$this->apiClient->updateBooking($formData);
try {
$this->cache->delete($cacheKeySingle);
$this->cache->delete($cacheKeyList);
$this->cache->delete($cacheKey);
} catch (InvalidArgumentException $e) {
}
+6 -23
View File
@@ -4,23 +4,19 @@ namespace App\Controller\Booking;
use App\BusProNet\ApiClient;
use App\BusProNet\XmlLoader\TravelLoader;
use Psr\Cache\InvalidArgumentException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Cache\ItemInterface;
class IndexController extends AbstractController
{
public function __construct(
private readonly ApiClient $apiClient,
private readonly TravelLoader $travelDataLoader,
private readonly CacheInterface $cache,
private readonly Security $security,
private readonly ApiClient $apiClient,
private readonly TravelLoader $travelDataLoader,
private readonly Security $security,
) {
}
@@ -34,24 +30,11 @@ class IndexController extends AbstractController
return $this->security->logout();
}
// Cache bookings for a short ttl
$cacheKey = sprintf('bpn_bookings_%s', sha1($bpnUser->getUserIdentifier()));
try {
$bookings = $this->cache->get($cacheKey, function (ItemInterface $item) use ($bpnUser) {
$item->expiresAfter(300);
$bookings = $this->apiClient->getBookings($bpnUser->getEmail(), $bpnUser->getPassword());
$this->travelDataLoader->patchBookings($bookings);
return $bookings;
});
$items = $bookings->getItems();
} catch (InvalidArgumentException $e) {
$items = [];
}
$bookings = $this->apiClient->getBookings($bpnUser->getEmail(), $bpnUser->getPassword());
$this->travelDataLoader->patchBookings($bookings);
return $this->render('booking/index.html.twig', [
'bookings' => $items,
'bookings' => $bookings->getItems(),
]);
}
}