Skip to content

Instantly share code, notes, and snippets.

@albertofem
Last active August 29, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save albertofem/2cccd25acddfe6129d4f to your computer and use it in GitHub Desktop.
Save albertofem/2cccd25acddfe6129d4f to your computer and use it in GitHub Desktop.
Symfony, Varnish, HTTP cache
backend default
{
.host = "127.0.0.1";
.port = "8080";
}
sub vcl_recv
{
if(req.http.X-Force-Backend)
{
return(pass);
}
if(req.http.Cookie && req.request ~ "(GET|HEAD)")
{
set req.http.X-Cookie = req.http.Cookie;
remove req.http.Cookie;
return(lookup);
}
}
sub vcl_deliver
{
if(resp.http.Cache-control ~ "(private|no-cache|no-store)"
&& !req.http.X-Force-Backend
&& req.request ~ "(GET|HEAD)"
)
{
set req.http.X-Force-Backend = "YES";
set req.http.Cookie = req.http.X-Cookie;
remove req.http.X-Cookie;
return(restart);
}
}
liip_cache_control:
rules:
- { path: ^/(admin|login|logout), controls: { public: false } }
- { controller: ^MyBundle:Controller:partial*, controls: { public: true, s_maxage: 3600, max_age: 3600, last_modified: "-1 hour" }}
- { path: ^/.*/custom-page, controls: { public: false }}
- { path: ^/.*/static-page*, controls: { public: true, max_age: 604800, s_maxage: 604800, last_modified: "-1 hour" } }
- { path: ^/$, controls: { public: true, max_age: 604800, s_maxage: 604800, last_modified: "-1 hour" }, vary: [Accept-Language] }
- { path: ^/, controls: { public: true, max_age: 604800, s_maxage: 604800, last_modified: "-1 hour" }, vary: [X-User-Language] } # this X-User-Language contains 'es', en', etc. instead of a long browser accept-language string
<?php
// ...
/**
* @Route("/partial-action", name="mybundle_controller_partial_whatever")
* @Template("MyBundle:Controller:_whatever.html.twig")
*/
public function partialWhateverAction()
{
// look something in the database
return [...];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment