3 declare(strict_types=1);
5 namespace CuyZ\Valinor\Mapper\Object\Factory;
7 use CuyZ\Valinor\Definition\ClassDefinition;
8 use CuyZ\Valinor\Mapper\Object\ObjectBuilder;
9 use Psr\SimpleCache\CacheInterface;
12 final class CacheObjectBuilderFactory implements ObjectBuilderFactory
14 public function __construct(
15 private ObjectBuilderFactory $delegate,
16 /** @var CacheInterface<list<ObjectBuilder>> */
17 private CacheInterface $cache
20 public function for(ClassDefinition $class): array
22 $signature = $class->type()->toString();
24 $entry = $this->cache->get($signature);
30 $builders = $this->delegate->for($class);
32 $this->cache->set($signature, $builders);