src/ResourceBuilder.php
public function build(array $data, ResourceInterface $resource = null)
    {
        $type = $data['sys']['type'];

        if ('Array' === $type) {
            $this->buildContentTypeCollection($data);
            $this->buildIncludes($data);

            return parent::build($data);
        }

        $resourceId = $data['sys']['id'];

        // Assets and entries are stored in cache using their locales.
        $locale = null;
        if (\in_array($data['sys']['type'], ['Asset', 'Entry'], true)) {
            $locale = $data['sys']['locale'] ?? '*';
        }

        if ($this->resourcePool->has($type, $resourceId, ['locale' => $locale])) {
            $resource = $this->resourcePool->get($type, $resourceId, ['locale' => $locale]);

            // If it's an entry, we still proceed with the resource building,
            // as it might have fields that were not previously loaded
            // due to the use of the select query operator.
            // For any other resource, we skip the building because
            // we have the result cached already.
            if ('Entry' !== $data['sys']['type']) {
                return $resource;
            }
        }

        $resource = parent::build($data, $resource);

        if ($resource instanceof ResourceInterface) {
            $this->resourcePool->save($resource);
        }

        return $resource;
    }
public function build(array $data, ResourceInterface $resource = null)
    {
        $type = $data['sys']['type'];

        if ('Array' === $type) {
            $this->buildContentTypeCollection($data);
            $this->buildIncludes($data);

            return parent::build($data);
        }

        $resourceId = $data['sys']['id'];

        // Assets and entries are stored in cache using their locales.
        $locale = null;
        if (\in_array($data['sys']['type'], ['Asset', 'Entry'], true)) {
            $locale = $data['sys']['locale'] ?? '*';
        }

        if ($this->resourcePool->has($type, $resourceId, ['locale' => $locale])) {
            $resource = $this->resourcePool->get($type, $resourceId, ['locale' => $locale]);

            // If it's an entry, we still proceed with the resource building,
            // as it might have fields that were not previously loaded
            // due to the use of the select query operator.
            // For any other resource, we skip the building because
            // we have the result cached already.
            if ('Entry' !== $data['sys']['type']) {
                return $resource;
            }
        }

        $resource = parent::build($data, $resource);

        if ($resource instanceof ResourceInterface) {
            $this->resourcePool->save($resource);
        }

        return $resource;
    }
{@inheritdoc}