buildStreamTag example


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

        foreach ($response->getResult() as $element) {
            $ids[] = $element->getStreamId();
        }

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

        return array_map(EntityCacheKeyGenerator::buildStreamTag(...)$ids);
    }

    /** * @return array<string> */
    private function extractProductIds(ProductCrossSellingRouteResponse $response): array
    {
        $ids = [];

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

        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
    {
        $generator = new EntityCacheKeyGenerator();

        static::assertSame($hash$generator->getCriteriaHash($criteria));
    }

    
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
    {
        // invalidates the category route cache when a category changed         $this->cacheInvalidator->invalidate(array_map(CachedCategoryRoute::buildName(...)$event->getIds()));
    }

    public function invalidateListingRouteByCategoryIds(CategoryIndexerEvent $event): void
    {
        


    /** * @return array<string> */
    private function generateTags(string $categoryId, Request $request, ProductListingRouteResponse $response, SalesChannelContext $context, Criteria $criteria): array
    {
        $streamId = $response->getResult()->getStreamId();

        $tags = array_merge(
            $this->tracer->get(self::buildName($categoryId)),
            [$streamId ? EntityCacheKeyGenerator::buildStreamTag($streamId) : null],
            [self::buildName($categoryId)]
        );

        $event = new ProductListingRouteCacheTagsEvent($tags$categoryId$request$response$context$criteria);
        $this->dispatcher->dispatch($event);

        return array_unique(array_filter($event->getTags()));
    }
}

            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())]];
    }
}

            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.