/
githubmirror
/
symfony
Обзор
Документация
Войти
/
githubmirror
/
symfony
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
8.2
src/Symfony/Component/RateLimiter/Storage/CacheStorage.php
53 строки
1 KB
Christian Flothmann
use constructor property promotion
29 май 2024, 12:56
29 май 2024, 12:56
943d430
Код
Авторство
О чём код?
<?php /* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@symfony.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\RateLimiter\Storage; use Psr\Cache\CacheItemPoolInterface; use Symfony\Component\RateLimiter\LimiterStateInterface; /** * @author Wouter de Jong <wouter@wouterj.nl> */ class CacheStorage implements StorageInterface { public function __construct( private CacheItemPoolInterface $pool, ) { } public function save(LimiterStateInterface $limiterState): void { $cacheItem = $this->pool->getItem(sha1($limiterState->getId())); $cacheItem->set($limiterState); if (null !== ($expireAfter = $limiterState->getExpirationTime())) { $cacheItem->expiresAfter($expireAfter); } $this->pool->save($cacheItem); } public function fetch(string $limiterStateId): ?LimiterStateInterface { $cacheItem = $this->pool->getItem(sha1($limiterStateId)); $value = $cacheItem->get(); if ($value instanceof LimiterStateInterface) { return $value; } return null; } public function delete(string $limiterStateId): void { $this->pool->deleteItem(sha1($limiterStateId)); } }