I'm Thomas Schedler @chirimoya | https://github.com/chirimoya ... head of development and technical consultant. Young father trying to master Heston Blumenthal recipes.
Browser Reverse Proxy Symfony Application GET / GET / Browser 200 OK Cache-Control: max-age=240 200 OK X-Reverse-Proxy-TTL: 3600 GET / GET / 200 OK X-Reverse-Proxy-TTL: 3600 200 OK Cache-Control: max-age=240 PURGE /
Browser Reverse Proxy Symfony Application GET / GET / Browser 200 OK Cache-Control: max-age=240 200 OK X-Reverse-Proxy-TTL: 3600 X-Cache-Tags: p1,p2,p3 GET / GET / 200 OK X-Reverse-Proxy-TTL: 3600 X-Cache-Tags: p1,p2 200 OK Cache-Control: max-age=240 BAN X-Cache-Tags: p3
ESI - Edge Side Includes – The ESI specification describes tags to communicate with the gateway cache – In Symfony the is implemented – If the response contains ESI tags, the cache either requests the page fragment from the backend or embeds the fresh cache entry
// src/Controller/NameController.php namespace App\Controller; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; class NameController { /** * @Route("/name/{name}") */ public function index(string $name) { $response = new Response('Your name is ' . $name); $response->setSharedMaxAge(3600); return $response; } }
Varnish Installation 1. Actually install varnish 2. Start varnish on port 80 3. Start your application on a different port 4. Tell varnish on which port your application is running 5. Add varnish as a trusted proxy in Symfony 6. Add cache headers to your responses 7. Configure the cache with VCL in more detail
// src/Controller/NameController.php namespace App\Controller; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; class NameController { /** * @Route("/name/{name}") */ public function index(string $name) { $response = new Response('Your name is ' . $name); $response->setSharedMaxAge(3600); return $response; } }
# default.vcl vcl 4.0; # Default backend definition. Set this to point to your content server. backend default { .host = ”127.0.0.1"; .port = "8080"; }
# default.vcl sub vcl_recv { # Happens before we check if we have this in cache already. # # Typically you clean up the request here, removing cookies you don't need, # rewriting the request, etc. } sub vcl_deliver { # Happens when we have all the pieces we need, and are about to send the # response to the client. # # You can do accounting or modifying the final object here. }
FOSHttpCacheBundle Features – Use rules to set cache headers – CacheManager / Annotations for comfortable Invalidation – Tagged Cache Invalidation – User Context based caching using session
Audience Targeting Goals – Differentiate between different visitor target groups – Target groups are evaluated by a ruleset – first visit – each browser session – each hit – Do not start a session on the server – Cache the response per target group