Last active
August 29, 2015 13:59
-
-
Save albertofem/2cccd25acddfe6129d4f to your computer and use it in GitHub Desktop.
Symfony, Varnish, HTTP cache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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