From 861a1a814617b6ea14323106aceb66b68fed4177 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Wed, 26 Aug 2026 09:45:49 +0200 Subject: [PATCH] fix(cache): resolve all cached brands before deleting collection key in BrandCache reset (F-2026-0002) --- src/Infra/Cache/BrandCache.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Infra/Cache/BrandCache.php b/src/Infra/Cache/BrandCache.php index 217c6e0..3a2c811 100644 --- a/src/Infra/Cache/BrandCache.php +++ b/src/Infra/Cache/BrandCache.php @@ -9,6 +9,7 @@ use Domain\Models\ValueObjects\Brand\ArcadiaId; use Domain\Models\ValueObjects\Brand\BrandCode; use Domain\Models\ValueObjects\Brand\BrandId; use Domain\Models\ValueObjects\Brand\BrandName; +use Psr\Log\LoggerInterface; use Psr\SimpleCache\CacheInterface; use Ramsey\Uuid\Uuid; @@ -20,7 +21,7 @@ final readonly class BrandCache public function __construct( private CacheInterface $cacheStore, - private \Psr\Log\LoggerInterface $logger, + private LoggerInterface $logger, ) { } @@ -30,6 +31,7 @@ final readonly class BrandCache return $this->fromCacheData($this->cacheStore->get($this->idKey($id))); } catch (\Throwable $e) { $this->logger->warning('BrandCache::getById failed', ['exception' => $e->getMessage()]); + return null; } } @@ -40,6 +42,7 @@ final readonly class BrandCache return $this->fromCacheData($this->cacheStore->get($this->codeKey($code))); } catch (\Throwable $e) { $this->logger->warning('BrandCache::getByCode failed', ['exception' => $e->getMessage()]); + return null; } } @@ -50,6 +53,7 @@ final readonly class BrandCache return $this->fromCacheData($this->cacheStore->get($this->arcadiaKey($arcadiaId))); } catch (\Throwable $e) { $this->logger->warning('BrandCache::getByArcadiaId failed', ['exception' => $e->getMessage()]); + return null; } } @@ -81,6 +85,7 @@ final readonly class BrandCache return $brands; } catch (\Throwable $e) { $this->logger->warning('BrandCache::getAll failed', ['exception' => $e->getMessage()]); + return null; } } @@ -127,9 +132,10 @@ final readonly class BrandCache public function reset(): void { try { + $all = $this->getAll(); + $this->cacheStore->delete(self::KEY_ALL); - $all = $this->getAll(); if ($all !== null) { foreach ($all as $brand) { $this->cacheStore->delete($this->idKey($brand->id()));