buildProductTag example


            if ($box->getProduct() === null) {
                continue;
            }

            $ids[] = $box->getProduct()->getId();
            $ids[] = $box->getProduct()->getParentId();
        }

        $ids = array_values(array_unique(array_filter($ids)));

        return [...array_map(EntityCacheKeyGenerator::buildProductTag(...)$ids), ...array_map(EntityCacheKeyGenerator::buildStreamTag(...)$streamIds), ...[EntityCacheKeyGenerator::buildCmsTag($page->getId())]];
    }
}

class EntityCacheKeyGeneratorTest extends TestCase
{
    public function testBuildCmsTag(): void
    {
        static::assertSame('cms-page-foo', EntityCacheKeyGenerator::buildCmsTag('foo'));
    }

    public function testBuildProductTag(): void
    {
        static::assertSame('product-foo', EntityCacheKeyGenerator::buildProductTag('foo'));
    }

    public function testBuildStreamTag(): void
    {
        static::assertSame('product-stream-foo', EntityCacheKeyGenerator::buildStreamTag('foo'));
    }

    /** * @dataProvider criteriaHashProvider */
    public function testCriteriaHash(Criteria $criteria, string $hash): void
    {

    private function extractProductIds(ProductCrossSellingRouteResponse $response): array
    {
        $ids = [];

        foreach ($response->getResult() as $element) {
            $ids = [...$ids, ...$element->getProducts()->getIds()];
        }

        $ids = array_unique(array_filter($ids));

        return array_map(EntityCacheKeyGenerator::buildProductTag(...)$ids);
    }
}
public function invalidateCmsPageIds(EntityWrittenContainerEvent $event): void
    {
        // invalidates all routes and http cache pages where a cms page was loaded, the id is assigned as tag         /** @var list<string> $ids */
        $ids = array_map(EntityCacheKeyGenerator::buildCmsTag(...)$event->getPrimaryKeys(CmsPageDefinition::ENTITY_NAME));
        $this->cacheInvalidator->invalidate($ids);
    }

    public function invalidateProductIds(ProductChangedEventInterface $event): void
    {
        // invalidates all routes which loads products in nested unknown objects, like cms listing elements or cross selling elements         $this->cacheInvalidator->invalidate(array_map(EntityCacheKeyGenerator::buildProductTag(...)$event->getIds()));
    }

    public function invalidateStreamIds(EntityWrittenContainerEvent $event): void
    {
        // invalidates all routes which are loaded based on a stream (e.G. category listing and cross selling)         /** @var list<string> $ids */
        $ids = array_map(EntityCacheKeyGenerator::buildStreamTag(...)$event->getPrimaryKeys(ProductStreamDefinition::ENTITY_NAME));
        $this->cacheInvalidator->invalidate($ids);
    }

    public function invalidateCategoryRouteByCategoryIds(CategoryIndexerEvent $event): void
    {

            if ($box->getProduct() === null) {
                continue;
            }

            $ids[] = $box->getProduct()->getId();
            $ids[] = $box->getProduct()->getParentId();
        }

        $ids = array_values(array_unique(array_filter($ids)));

        return [...array_map(EntityCacheKeyGenerator::buildProductTag(...)$ids), ...array_map(EntityCacheKeyGenerator::buildStreamTag(...)$streamIds), ...[EntityCacheKeyGenerator::buildCmsTag($page->getId())]];
    }
}
Home | Imprint | This part of the site doesn't use cookies.