update code, add psalm
This commit is contained in:
parent
427d474f7c
commit
224925e56b
8 changed files with 1909 additions and 7 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue