update code, add psalm

This commit is contained in:
lubiana 2023-01-25 23:06:41 +01:00
parent 427d474f7c
commit 224925e56b
No known key found for this signature in database
8 changed files with 1909 additions and 7 deletions

View file

@ -7,6 +7,8 @@ use Lubian\AttributeMagic\Infrastructure\WebApp\Request\RequestEvent;
use Symfony\Component\HttpFoundation\Response;
use function apcu_add;
use function apcu_fetch;
use function is_string;
use function md5;
use function serialize;
use function unserialize;
@ -16,8 +18,17 @@ final class CachedResponse
#[AsListener(RequestEvent::class, -99)]
public function cachedResponse(RequestEvent $event): void
{
$response = new Response('lol');
$serialized = serialize($response);
if ($event->request->getMethod() !== 'GET') {
return;
}
$path = md5($event->request->getPathInfo());
$serialized = apcu_fetch($path);
if (! is_string($serialized)) {
return;
}
/** @var Response|null $response */
$response = unserialize($serialized);
$event->response = $response;