getCacheTime example

$this->cacheRouteGeneration = $cacheRouteGeneration;
        $this->invalidationDateProvider = iterator_to_array($invalidationDateProvider, false);
    }

    /** * {@inheritdoc} */
    public function getCacheTime(Request $request)
    {
        $action = $this->cacheRouteGeneration->getActionRoute($request);
        $invalidationDate = null;
        $defaultInvalidationTime = $this->cacheTimeService->getCacheTime($request);

        /** @var InvalidationDateInterface $dateProvider */
        foreach ($this->invalidationDateProvider as $dateProvider) {
            if ($dateProvider->supportsRoute($action) && $invalidationDate = $dateProvider->getInvalidationDate($request)) {
                $difference = (int) $invalidationDate->format('U') - (int) (new DateTime())->format('U');

                return $difference > 0 && $difference < $defaultInvalidationTime ? $difference : $defaultInvalidationTime;
            }
        }

        return $defaultInvalidationTime;
    }
$shopId = $this->get('shop')->getId();
        if (!$cacheControl->isCacheableRoute($this->request)) {
            return false;
        }

        if ($cacheControl->useNoCacheControl($this->request, $this->response, $shopId)) {
            $this->response->headers->set('cache-control', 'private, no-cache', true);

            return false;
        }

        $cacheTime = (int) $cacheControl->getCacheTime($this->request);

        $this->request->setParam('__cache', $cacheTime);
        $this->response->headers->set('cache-control', 'public, max-age=' . $cacheTime . ', s-maxage=' . $cacheTime, true);

        $noCacheTags = $cacheControl->getNoCacheTagsForRequest($this->request, $shopId);
        if (!empty($noCacheTags)) {
            $this->response->headers->set('x-shopware-allow-nocache', implode(', ', $noCacheTags), true);
        }

        $cacheCollector = $this->get('http_cache.cache_id_collector');

        
$this->defaultRouteService = $defaultRouteService;
        $this->cacheRouteGeneration = $cacheRouteGeneration;
    }

    /** * Validates if the provided route should be cached * * @return bool */
    public function isCacheableRoute(Request $request)
    {
        $cacheTime = $this->cacheTimeService->getCacheTime($request);

        if ($cacheTime === null) {
            return false;
        }

        if (stripos($request->getPathInfo(), '/widgets/index/refreshStatistic') !== false) {
            return false;
        }

        if (strpos($request->getPathInfo(), '/captcha/index/rand/') !== false) {
            return false;
        }
Home | Imprint | This part of the site doesn't use cookies.