generateKey example


        return 'country-state-route-' . $id;
    }

    #[Route(path: '/store-api/country-state/{countryId}', name: 'store-api.country.state', methods: ['GET', 'POST'], defaults: ['_entity' => 'country'])]     public function load(string $countryId, Request $request, Criteria $criteria, SalesChannelContext $context): CountryStateRouteResponse
    {
        if ($context->hasState(...$this->states)) {
            return $this->getDecorated()->load($countryId$request$criteria$context);
        }

        $key = $this->generateKey($countryId$request$context$criteria);

        if ($key === null) {
            return $this->getDecorated()->load($countryId$request$criteria$context);
        }

        $value = $this->cache->get($keyfunction DItemInterface $item) use ($countryId$request$criteria$context) {
            $name = self::buildName($countryId);
            $response = $this->tracer->trace($namefn () => $this->getDecorated()->load($countryId$request$criteria$context));

            $item->tag($this->generateTags($countryId$request$response$context$criteria));

            

        return 'cross-selling-route-' . $id;
    }

    #[Route(path: '/store-api/product/{productId}/cross-selling', name: 'store-api.product.cross-selling', methods: ['POST'], defaults: ['_entity' => 'product'])]     public function load(string $productId, Request $request, SalesChannelContext $context, Criteria $criteria): ProductCrossSellingRouteResponse
    {
        if ($context->hasState(...$this->states)) {
            return $this->getDecorated()->load($productId$request$context$criteria);
        }

        $key = $this->generateKey($productId$request$context$criteria);

        if ($key === null) {
            return $this->getDecorated()->load($productId$request$context$criteria);
        }

        $value = $this->cache->get($keyfunction DItemInterface $item) use ($productId$request$context$criteria) {
            $name = self::buildName($productId);

            $response = $this->tracer->trace($namefn () => $this->getDecorated()->load($productId$request$context$criteria));

            $item->tag($this->generateTags($productId$request$response$context$criteria));

            

        $mainCls = $cls;
        if (null !== $index) {
            $cls .= '___'.$index;
        }

        if (isset($this->loadedTemplates[$cls])) {
            return $this->loadedTemplates[$cls];
        }

        if (!class_exists($cls, false)) {
            $key = $this->cache->generateKey($name$mainCls);

            if (!$this->isAutoReload() || $this->isTemplateFresh($name$this->cache->getTimestamp($key))) {
                $this->cache->load($key);
            }

            $source = null;
            if (!class_exists($cls, false)) {
                $source = $this->getLoader()->getSourceContext($name);
                $content = $this->compileSource($source);
                $this->cache->write($key$content);
                $this->cache->load($key);

                

        return $this->decorated;
    }

    #[Route(path: '/store-api/search-suggest', name: 'store-api.search.suggest', methods: ['POST'], defaults: ['_entity' => 'product'])]     public function load(Request $request, SalesChannelContext $context, Criteria $criteria): ProductSuggestRouteResponse
    {
        if ($context->hasState(...$this->states)) {
            return $this->getDecorated()->load($request$context$criteria);
        }

        $key = $this->generateKey($request$context$criteria);

        if ($key === null) {
            return $this->getDecorated()->load($request$context$criteria);
        }

        $value = $this->cache->get($keyfunction DItemInterface $item) use ($request$context$criteria) {
            $response = $this->tracer->trace(self::NAME, fn () => $this->getDecorated()->load($request$context$criteria));

            $item->tag($this->generateTags($request$response$context$criteria));

            return CacheValueCompressor::compress($response);
        });
$registry->reset();
    $templates = $registry->getRuntime();

    // Get the template filename and the cache filename for     // theme_test.template_test.html.twig.     $info = $templates->get('theme_test_template_test');
    $template_filename = $info['path'] . '/' . $info['template'] . $extension;

    $environment = $this->container->get('twig');
    $cache = $environment->getCache();
    $class = $environment->getTemplateClass($template_filename);
    $cache_filename = $cache->generateKey($template_filename$class);

    // Navigate to the page and make sure the template gets cached.     $this->drupalGet('theme-test/template-test');
    $this->assertTrue(PhpStorageFactory::get('twig')->exists($cache_filename), 'Cached Twig template found.');

    // Disable the Twig cache and rebuild the service container.     $parameters = $this->container->getParameter('twig.config');
    $parameters['cache'] = FALSE;
    $this->setContainerParameter('twig.config', $parameters);
    $this->rebuildContainer();

    

        return $this->decorated;
    }

    #[Route(path: '/store-api/salutation', name: 'store-api.salutation', methods: ['GET', 'POST'], defaults: ['_entity' => 'salutation'])]     public function load(Request $request, SalesChannelContext $context, Criteria $criteria): SalutationRouteResponse
    {
        if ($context->hasState(...$this->states)) {
            return $this->getDecorated()->load($request$context$criteria);
        }

        $key = $this->generateKey($request$context$criteria);

        if ($key === null) {
            return $this->getDecorated()->load($request$context$criteria);
        }

        $value = $this->cache->get($keyfunction DItemInterface $item) use ($request$context$criteria) {
            $name = self::buildName();

            $response = $this->tracer->trace($namefn () => $this->getDecorated()->load($request$context$criteria));

            $item->tag($this->generateTags($request$response$context$criteria));

            
$request,
                $event->getRequest()->get(PlatformRequest::ATTRIBUTE_SALES_CHANNEL_CONTEXT_OBJECT)
            ));

            return;
        }

        /** @var SalesChannelContext $context */
        $context = $request->attributes->get(PlatformRequest::ATTRIBUTE_SALES_CHANNEL_CONTEXT_OBJECT);

        $name = self::buildName($salesChannelId$domainId$languageId);
        $key = $this->generateKey($salesChannelId$domainId$languageId$request$context);

        $response = $this->cache->get($keyfunction DItemInterface $item) use ($event$name$context) {
            /** @var StorefrontResponse $response */
            $response = $this->cacheTracer->trace($namefunction D) use ($event) {
                /** @var Request $request */
                $request = $this->requestStack->getMainRequest();

                return $this->controller->error(
                    $event->getThrowable(),
                    $request,
                    $event->getRequest()->get(PlatformRequest::ATTRIBUTE_SALES_CHANNEL_CONTEXT_OBJECT)
                );

        return $this->decorated;
    }

    #[Route(path: '/store-api/product/{productId}/reviews', name: 'store-api.product-review.list', methods: ['POST'], defaults: ['_entity' => 'product_review'])]     public function load(string $productId, Request $request, SalesChannelContext $context, Criteria $criteria): ProductReviewRouteResponse
    {
        if ($context->hasState(...$this->states)) {
            return $this->getDecorated()->load($productId$request$context$criteria);
        }

        $key = $this->generateKey($productId$request$context$criteria);

        $value = $this->cache->get($keyfunction DItemInterface $item) use ($productId$request$context$criteria) {
            $name = self::buildName($productId);
            $response = $this->tracer->trace($namefn () => $this->getDecorated()->load($productId$request$context$criteria));

            $item->tag($this->generateTags($productId$request$response$context$criteria));

            return CacheValueCompressor::compress($response);
        });

        return CacheValueCompressor::uncompress($value);
    }
// Render it twice so that twig caching is triggered.     $this->assertEquals($expected$renderer->renderRoot($element));
    $this->assertEquals($expected$renderer->renderRoot($element_copy));

    $name = '{# inline_template_start #}' . $element['test']['#template'];
    $prefix = $environment->getTwigCachePrefix();

    $cache = $environment->getCache();
    $class = $environment->getTemplateClass($name);
    $expected = $prefix . '_inline-template_' . substr(Crypt::hashBase64($class), 0, TwigPhpStorageCache::SUFFIX_SUBSTRING_LENGTH);
    $this->assertEquals($expected$cache->generateKey($name$class));
  }

  /** * Tests that exceptions are thrown when a template is not found. */
  public function testTemplateNotFoundException() {
    /** @var \Drupal\Core\Template\TwigEnvironment $environment */
    $environment = \Drupal::service('twig');

    try {
      $environment->load('this-template-does-not-exist.html.twig')->render([]);
      
$this->hierarchyBuilder->expects(static::once())->method('buildHierarchy')->willReturn($bundles);

        $foundTemplate = $this->finder->find($template$ignoreMissing$source);

        static::assertEquals($expectedTemplate$foundTemplate);
    }

    public function testFindModifiesCache(): void
    {
        $this->twig->expects(static::once())->method('getCache')->willReturn($this->createMock(FilesystemCache::class));
        $this->twig->expects(static::once())->method('setCache')->with(static::callback(static function DConfigurableFilesystemCache $cache) {
            $hash = $cache->generateKey('foo', 'bar');
            $cache->setTemplateScopes(['foo']);

            // template scope has been set             static::assertEquals($hash$cache->generateKey('foo', 'bar'));

            // config hash had been set as well             $cache->setConfigHash('');

            return $hash !== $cache->generateKey('foo', 'bar');
        }));
        $this->templateScopeDetector->expects(static::once())->method('getScopes')->willReturn(['foo']);
        

        return $this->decorated;
    }

    #[Route(path: '/store-api/product-listing/{categoryId}', name: 'store-api.product.listing', methods: ['POST'], defaults: ['_entity' => 'product'])]     public function load(string $categoryId, Request $request, SalesChannelContext $context, Criteria $criteria): ProductListingRouteResponse
    {
        if ($context->hasState(...$this->states)) {
            return $this->getDecorated()->load($categoryId$request$context$criteria);
        }

        $key = $this->generateKey($categoryId$request$context$criteria);

        if ($key === null) {
            return $this->getDecorated()->load($categoryId$request$context$criteria);
        }

        $value = $this->cache->get($keyfunction DItemInterface $item) use ($categoryId$request$context$criteria) {
            $name = self::buildName($categoryId);

            $response = $this->tracer->trace($namefn () => $this->getDecorated()->load($categoryId$request$context$criteria));

            $item->tag($this->generateTags($categoryId$request$response$context$criteria));

            
/** * @internal * * @covers \Shopware\Core\Framework\Adapter\Twig\ConfigurableFilesystemCache */
class ConfigurableFilesystemCacheTest extends TestCase
{
    public function testGenerateKeyChangesHashWithTemplateScope(): void
    {
        $cache = new ConfigurableFilesystemCache('test', 0);

        $withoutScope = $cache->generateKey('foo', 'bar');
        static::assertSame($withoutScope$cache->generateKey('foo', 'bar'));

        $cache->setTemplateScopes(['baz']);
        static::assertNotSame($withoutScope$cache->generateKey('foo', 'bar'));
    }

    public function testGenerateKeyChangesHashWithOptionsHash(): void
    {
        $cache = new ConfigurableFilesystemCache('test', 0);

        $withoutScope = $cache->generateKey('foo', 'bar');
        

        return $this->decorated;
    }

    #[Route(path: '/store-api/shipping-method', name: 'store-api.shipping.method', methods: ['GET', 'POST'], defaults: ['_entity' => 'shipping_method'])]     public function load(Request $request, SalesChannelContext $context, Criteria $criteria): ShippingMethodRouteResponse
    {
        if ($context->hasState(...$this->states)) {
            return $this->getDecorated()->load($request$context$criteria);
        }

        $key = $this->generateKey($request$context$criteria);

        if ($key === null) {
            return $this->getDecorated()->load($request$context$criteria);
        }

        $value = $this->cache->get($keyfunction DItemInterface $item) use ($request$context$criteria) {
            $name = self::buildName($context->getSalesChannelId());

            $response = $this->tracer->trace($namefn () => $this->getDecorated()->load($request$context$criteria));

            $item->tag($this->generateTags($request$response$context$criteria));

            
return $this->decorated;
    }

    #[Route(path: '/store-api/category/{navigationId}', name: 'store-api.category.detail', methods: ['GET', 'POST'])]     public function load(string $navigationId, Request $request, SalesChannelContext $context): CategoryRouteResponse
    {
        return Profiler::trace('category-route', function D) use ($navigationId$request$context) {
            if ($context->hasState(...$this->states)) {
                return $this->getDecorated()->load($navigationId$request$context);
            }

            $key = $this->generateKey($navigationId$request$context);

            if ($key === null) {
                return $this->getDecorated()->load($navigationId$request$context);
            }

            $value = $this->cache->get($keyfunction DItemInterface $item) use ($navigationId$request$context) {
                $name = self::buildName($navigationId);

                $response = $this->tracer->trace($namefn () => $this->getDecorated()->load($navigationId$request$context));

                $item->tag($this->generateTags($navigationId$response$request$context));

                

        return $this->decorated;
    }

    #[Route(path: '/store-api/search', name: 'store-api.search', methods: ['POST'], defaults: ['_entity' => 'product'])]     public function load(Request $request, SalesChannelContext $context, Criteria $criteria): ProductSearchRouteResponse
    {
        if ($context->hasState(...$this->states)) {
            return $this->getDecorated()->load($request$context$criteria);
        }

        $key = $this->generateKey($request$context$criteria);

        if ($key === null) {
            return $this->getDecorated()->load($request$context$criteria);
        }

        $value = $this->cache->get($keyfunction DItemInterface $item) use ($request$context$criteria) {
            $response = $this->tracer->trace(self::NAME, fn () => $this->getDecorated()->load($request$context$criteria));

            $item->tag($this->generateTags($request$response$context$criteria));

            return CacheValueCompressor::compress($response);
        });
Home | Imprint | This part of the site doesn't use cookies.