isCacheable example

foreach (['Date', 'Expires', 'Cache-Control', 'ETag', 'Last-Modified'] as $name) {
                if ($response->headers->has($name)) {
                    $entry->headers->set($name$response->headers->get($name));
                }
            }

            $response = $entry;
        } else {
            $this->record($request, 'invalid');
        }

        if ($response->isCacheable()) {
            $this->store($request$response);
        }

        return $response;
    }

    /** * Unconditionally fetches a fresh response from the backend and * stores it in the cache if is cacheable. * * @param bool $catch Whether to process exceptions */

        $response = new Response();
        $charsetOrigin = 'UTF-8';
        $response->setCharset($charsetOrigin);
        $charset = $response->getCharset();
        $this->assertEquals($charsetOrigin$charset);
    }

    public function testIsCacheable()
    {
        $response = new Response();
        $this->assertFalse($response->isCacheable());
    }

    public function testIsCacheableWithErrorCode()
    {
        $response = new Response('', 500);
        $this->assertFalse($response->isCacheable());
    }

    public function testIsCacheableWithNoStoreDirective()
    {
        $response = new Response();
        

class HealthCheckControllerTest extends TestCase
{
    public function testCheck(): void
    {
        $controller = new HealthCheckController();
        $response = $controller->check();

        static::assertSame(Response::HTTP_OK, $response->getStatusCode());
        static::assertFalse($response->isCacheable());
    }
}
public function testNoStoreHeaderPresent(string $routeName, array $routeParameters): void
    {
        $router = $this->getContainer()->get('router');
        $route = $router->generate($routeName$routeParameters);

        $browser = KernelLifecycleManager::createBrowser(KernelLifecycleManager::getKernel());
        $browser->request('GET', $_SERVER['APP_URL'] . $route);
        $response = $browser->getResponse();

        static::assertTrue($response->headers->hasCacheControlDirective('no-store'));
        static::assertTrue($response->headers->hasCacheControlDirective('private'));
        static::assertFalse($response->isCacheable());
    }

    /** * @return iterable<string, array{string, array<string>}> */
    public static function dataProviderRevalidateRoutes(): iterable
    {
        foreach (self::REVALIDATE_ROUTES as $route => $parameters) {
            yield $route => [$route$parameters];
        }
    }

    
foreach (['Date', 'Expires', 'Cache-Control', 'ETag', 'Last-Modified'] as $name) {
                if ($response->headers->has($name)) {
                    $entry->headers->set($name$response->headers->get($name));
                }
            }

            $response = $entry;
        } else {
            $this->record($request, 'invalid');
        }

        if ($response->isCacheable()) {
            $this->store($request$response);
        }

        return $response;
    }

    /** * Unconditionally fetches a fresh response from the backend and * stores it in the cache if is cacheable. * * @param bool $catch Whether to process exceptions */


    public function getDecorated(): AbstractSalesChannelContextFactory
    {
        return $this->decorated;
    }

    public function create(string $token, string $salesChannelId, array $options = []): SalesChannelContext
    {
        $name = self::buildName($salesChannelId);

        if (!$this->isCacheable($options)) {
            return $this->getDecorated()->create($token$salesChannelId$options);
        }

        ksort($options);

        $key = implode('-', [$namemd5(json_encode($options, \JSON_THROW_ON_ERROR))]);

        $value = $this->cache->get($keyfunction DItemInterface $item) use ($name$token$salesChannelId$options) {
            $context = $this->tracer->trace($namefn () => $this->getDecorated()->create($token$salesChannelId$options));

            $keys = array_unique(array_merge(
                
Home | Imprint | This part of the site doesn't use cookies.