3 declare(strict_types=1);
5 namespace CuyZ\Valinor\Definition\Repository\Cache;
7 use CuyZ\Valinor\Definition\ClassDefinition;
8 use CuyZ\Valinor\Definition\Repository\ClassDefinitionRepository;
9 use CuyZ\Valinor\Type\ClassType;
10 use Psr\SimpleCache\CacheInterface;
13 final class CacheClassDefinitionRepository implements ClassDefinitionRepository
15 public function __construct(
16 private ClassDefinitionRepository $delegate,
17 /** @var CacheInterface<ClassDefinition> */
18 private CacheInterface $cache
21 public function for(ClassType $type): ClassDefinition
23 $key = "class-definition-{$type->toString()}";
25 $entry = $this->cache->get($key);
31 $class = $this->delegate->for($type);
33 $this->cache->set($key, $class);