move code to repository root
This commit is contained in:
parent
47e227257c
commit
9ce2c0ae4c
35 changed files with 2025 additions and 0 deletions
38
src/Infrastructure/WebApp/Route/CachedResponse.php
Normal file
38
src/Infrastructure/WebApp/Route/CachedResponse.php
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Lubian\AttributeMagic\Infrastructure\WebApp\Route;
|
||||
|
||||
use Lubian\AttributeMagic\Infrastructure\Event\AsListener;
|
||||
use Lubian\AttributeMagic\Infrastructure\WebApp\Request\RequestEvent;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
use function apcu_add;
|
||||
use function md5;
|
||||
use function serialize;
|
||||
use function unserialize;
|
||||
|
||||
final class CachedResponse
|
||||
{
|
||||
#[AsListener(RequestEvent::class, -99)]
|
||||
public function cachedResponse(RequestEvent $event): void
|
||||
{
|
||||
$response = new Response('lol');
|
||||
$serialized = serialize($response);
|
||||
/** @var Response|null $response */
|
||||
$response = unserialize($serialized);
|
||||
$event->response = $response;
|
||||
|
||||
$event->stopped = true;
|
||||
}
|
||||
|
||||
#[AsListener(RequestEvent::class, 99)]
|
||||
public function doCache(RequestEvent $event): void
|
||||
{
|
||||
if ($event->response === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$path = md5($event->request->getPathInfo());
|
||||
apcu_add($path, serialize($event->response));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue