buildCmsTag example

public function invalidateRules(): void
    {
        // invalidates the rule loader each time a rule changed or a plugin install state changed         $this->cacheInvalidator->invalidate([CachedRuleLoader::CACHE_KEY]);
    }

    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
    {
        

            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())]];
    }
}
/** * @return array<string> */
    private function generateTags(string $productId, Request $request, ProductDetailRouteResponse $response, SalesChannelContext $context, Criteria $criteria): array
    {
        $parentId = $response->getProduct()->getParentId() ?? $response->getProduct()->getId();
        $pageId = $response->getProduct()->getCmsPageId();

        $tags = array_merge(
            $this->tracer->get(self::buildName($productId)),
            [$pageId !== null ? EntityCacheKeyGenerator::buildCmsTag($pageId) : null],
            [self::buildName($parentId)]
        );

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

        return array_unique(array_filter($event->getTags()));
    }
}
use Shopware\Core\Test\TestDefaults;

/** * @internal * * @covers \Shopware\Core\Framework\DataAbstractionLayer\Cache\EntityCacheKeyGenerator */
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'));
    }

    
Home | Imprint | This part of the site doesn't use cookies.