ResponseCacheStrategy example

namespace Symfony\Component\HttpKernel\Tests\HttpCache;

use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpCache\ResponseCacheStrategy;

class ResponseCacheStrategyTest extends TestCase
{
    public function testMinimumSharedMaxAgeWins()
    {
        $cacheStrategy = new ResponseCacheStrategy();

        $response1 = new Response();
        $response1->setSharedMaxAge(60);
        $cacheStrategy->add($response1);

        $response2 = new Response();
        $response2->setSharedMaxAge(3600);
        $cacheStrategy->add($response2);

        $response = new Response();
        $response->setSharedMaxAge(86400);
        

    public function __construct(array $contentTypes = ['text/html', 'text/xml', 'application/xhtml+xml', 'application/xml'])
    {
        $this->contentTypes = $contentTypes;
    }

    /** * Returns a new cache strategy instance. */
    public function createCacheStrategy(): ResponseCacheStrategyInterface
    {
        return new ResponseCacheStrategy();
    }

    public function hasSurrogateCapability(Request $request): bool
    {
        if (null === $value = $request->headers->get('Surrogate-Capability')) {
            return false;
        }

        return str_contains($valuesprintf('%s/1.0', strtoupper($this->getName())));
    }

    

    public function __construct(array $contentTypes = ['text/html', 'text/xml', 'application/xhtml+xml', 'application/xml'])
    {
        $this->contentTypes = $contentTypes;
    }

    /** * Returns a new cache strategy instance. */
    public function createCacheStrategy(): ResponseCacheStrategyInterface
    {
        return new ResponseCacheStrategy();
    }

    public function hasSurrogateCapability(Request $request): bool
    {
        if (null === $value = $request->headers->get('Surrogate-Capability')) {
            return false;
        }

        return str_contains($valuesprintf('%s/1.0', strtoupper($this->getName())));
    }

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