uncompress example

$item = $this->cache->getItem($cacheKey);

        try {
            if (!$item->isHit() || !$item->get()) {
                $this->logger->info('cache-miss: ' . $request->getPathInfo());

                return null;
            }

            /** @var Response $response */
            $response = CacheCompressor::uncompress($item);
        } catch (\Throwable $e) {
            $this->logger->error($e->getMessage());

            return null;
        }

        $invalidationStates = explode(',', (string) $response->headers->get(self::INVALIDATION_STATES_HEADER));
        if ($context->hasState(...$invalidationStates)) {
            $this->logger->info('cache-miss: ' . $request->getPathInfo());

            return null;
        }

        return ['script.written' => 'invalidateCache'];
    }

    /** * @return Script[] */
    public function get(string $hook): array
    {
        $cacheItem = $this->cache->getItem(self::CACHE_KEY);
        if ($cacheItem->isHit() && $cacheItem->get() && !$this->debug) {
            return CacheCompressor::uncompress($cacheItem)[$hook] ?? [];
        }

        $scripts = $this->load();

        $cacheItem = CacheCompressor::compress($cacheItem$scripts);
        $this->cache->save($cacheItem);

        return $scripts[$hook] ?? [];
    }

    public function invalidateCache(): void
    {
$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);
    }

    public static function buildName(string $parentId): string
    {
        return 'product-detail-route-' . $parentId;
    }

    private function generateKey(string $productId, Request $request, SalesChannelContext $context, Criteria $criteria): ?string
    {
        $parts = [
            $this->generator->getCriteriaHash($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);
    }

    private function generateKey(string $productId, Request $request, SalesChannelContext $context, Criteria $criteria): ?string
    {
        $parts = [
            $this->generator->getCriteriaHash($criteria),
            $this->generator->getSalesChannelContextHash($context[RuleAreas::PRODUCT_AREA]),
        ];

        $event = new CrossSellingRouteCacheKeyEvent($productId$parts$request$context$criteria);
        $this->dispatcher->dispatch($event);

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

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

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

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

        return CacheValueCompressor::uncompress($value);
    }

    private function generateKey(Request $request, SalesChannelContext $context): ?string
    {
        $parts = [$this->generator->getSalesChannelContextHash($context)];

        $event = new SitemapRouteCacheKeyEvent($parts$request$context, null);
        $this->dispatcher->dispatch($event);

        if (!$event->shouldCache()) {
            return null;
        }
return $item;
    }

    /** * @return TCachedContent */
    public static function uncompress(CacheItem $item)
    {
        /** @var TCachedContent|string $value */
        $value = $item->get();

        return CacheValueCompressor::uncompress($value);
    }
}
$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$criteria$context));

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

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

        return CacheValueCompressor::uncompress($value);
    }

    protected function getDecorated(): AbstractCountryRoute
    {
        return $this->decorated;
    }

    private function generateKey(Request $request, SalesChannelContext $context, Criteria $criteria): ?string
    {
        $parts = [
            $this->generator->getCriteriaHash($criteria),
            

    public static function compress($ip)
    {
        // Prepare the IP to be compressed         $ip = self::uncompress($ip);
        $ip_parts = self::split_v6_v4($ip);

        // Replace all leading zeros         $ip_parts[0] = preg_replace('/(^|:)0+([0-9])/', '\1\2', $ip_parts[0]);

        // Find bunches of zeros         if (preg_match_all('/(?:^|:)(?:0(?::|$))+/', $ip_parts[0]$matches, PREG_OFFSET_CAPTURE))
        {
            $max = 0;
            $pos = null;
            foreach ($matches[0] as $match)
            {

        $key = 'system-config-' . $salesChannelId;

        $value = $this->cache->get($keyfunction DItemInterface $item) use ($salesChannelId) {
            $config = $this->getDecorated()->load($salesChannelId);

            $item->tag([self::CACHE_TAG]);

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

        return CacheValueCompressor::uncompress($value);
    }
}
$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));

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

        return CacheValueCompressor::uncompress($value);
    }

    public static function buildName(string $categoryId): string
    {
        return 'product-listing-route-' . $categoryId;
    }

    private function generateKey(string $categoryId, Request $request, SalesChannelContext $context, Criteria $criteria): ?string
    {
        $parts = [
            $this->generator->getCriteriaHash($criteria),
            
try {
            $value = \unserialize($value);
        } catch (\Exception) {
            throw CartException::tokenNotFound($token);
        }

        if (!isset($value['compressed'])) {
            throw CartException::tokenNotFound($token);
        }

        $content = $value['compressed'] ? CacheValueCompressor::uncompress($value['content']) : \unserialize((string) $value['content']);

        if (!\is_array($content)) {
            throw CartException::tokenNotFound($token);
        }

        $cart = $content['cart'];

        if (!$cart instanceof Cart) {
            throw CartException::deserializeFailed();
        }

        
$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 CacheValueCompressor::compress($response);
        });

        return CacheValueCompressor::uncompress($value);
    }

    public static function buildName(string $salesChannelId): string
    {
        return 'payment-method-route-' . $salesChannelId;
    }

    private function generateKey(Request $request, SalesChannelContext $context, Criteria $criteria): ?string
    {
        $parts = [
            $this->generator->getCriteriaHash($criteria),
            
continue;
            }

            $value = \unserialize($value);

            if (!\array_key_exists('sales_channel_id', $value)) {
                $this->io->writeln('<error>Sales channel id is missing for key ' . $key . '. Carts created before 6.4.12 can not be migrated</error>');

                continue;
            }

            $content = $value['compressed'] ? CacheValueCompressor::uncompress($value['content']) : \unserialize($value['content']);

            unset($value['content']$value['compressed']);

            // @deprecated tag:v6.6.0 - payload always exists - keep IF body             if ($payloadExists) {
                $value['payload'] = $this->compress ? CacheValueCompressor::compress($content['cart']) : serialize($content['cart']);
                $value['compressed'] = $this->compress ? 1 : 0;
            } else {
                $value['cart'] = serialize($content['cart']);
            }

            


        $key = $this->cacheKeyGenerator->generate($request);

        $item = $this->cache->getItem($key);

        if (!$item->isHit() || !$item->get()) {
            return null;
        }

        /** @var Response $response */
        $response = CacheCompressor::uncompress($item);

        if (!$this->stateValidator->isValid($request$response)) {
            return null;
        }

        $this->eventDispatcher->dispatch(
            new HttpCacheHitEvent($item$request$response)
        );

        return $response;
    }

    
static::assertEquals('product-page-loaded', $script->getHook());
        static::assertStringEqualsFile(
            __DIR__ . '/../Manifest/_fixtures/test/Resources/scripts/product-page-loaded/product-page-script.twig',
            $script->getScript()
        );
        static::assertEquals($active$script->isActive());

        $cache = $this->getContainer()->get('cache.object');
        static::assertTrue($cache->hasItem(ScriptLoader::CACHE_KEY));

        $item = $cache->getItem(ScriptLoader::CACHE_KEY);
        $cachedScripts = CacheCompressor::uncompress($item);
        static::assertArrayHasKey('product-page-loaded', $cachedScripts);
        static::assertCount(1, $cachedScripts['product-page-loaded']);
        static::assertInstanceOf(Script::class$cachedScripts['product-page-loaded'][0]);
        static::assertEquals($script->getName()$cachedScripts['product-page-loaded'][0]->getName());
    }

    private function assertDefaultPaymentMethods(string $appId): void
    {
        /** @var EntityRepository $paymentMethodRepository */
        $paymentMethodRepository = $this->getContainer()->get('payment_method.repository');

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