In the first part of the presentation we see how Symfony2 implements HTTP cache.
In the second one there's an explanation of why application cache layers suck, why nerly every php application does caching in the less productive way and how you benefit from HTTP cache from this point of view.
36. what's the advatage of using validation if we always hit
the DB and create a new Response?
37. Validation, the right way
public function articleAction($id)
{
$res = new Response()
$etag = Memcache::get("Article:{$id}:etag");
$lastModified = Memcache::get("Article:{$id}:last_modified");
$res->setETag($etag);
$res->setLastModified($lastModified);
if ($res->isNotModified($this->get('request'))) {
return $res;
}
$article = $this->get('entity_manager')->query($id)...
...
38. Validation, the right way
public function articleAction($id)
{
$res = new Response()
$etag = Memcache::get("Article:{$id}:etag");
$lastModified = Memcache::get("Article:{$id}:last_modified");
$res->setETag($etag);
$res->setLastModified($lastModified);
if ($res->isNotModified($this->get('request'))) {
return $res;
}
$article = $this->get('entity_manager')->query($id)...
...
39. Validation, the right way
public function articleAction($id)
{
$res = new Response()
$etag = Memcache::get("Article:{$id}:etag");
$lastModified = Memcache::get("Article:{$id}:last_modified");
$res->setETag($etag);
$res->setLastModified($lastModified);
if ($res->isNotModified($this->get('request'))) {
return $res;
}
$article = $this->get('entity_manager')->query($id)...
...
40. Validation, the right way
public function articleAction($id)
{
$res = new Response()
$etag = Memcache::get("Article:{$id}:etag");
$lastModified = Memcache::get("Article:{$id}:last_modified");
$res->setETag($etag);
$res->setLastModified($lastModified);
if ($res->isNotModified($this->get('request'))) {
return $res;
}
$article = $this->get('entity_manager')->query($id)...
...
44. Additional management
public function articleAction($id)
{
$res = new Response()
$res->setVary(array(
'Accept-Encoding',
));
$res->setPublic();
$res->setNotModified();
...
45. Varying the response
public function articleAction($id)
{
$res = new Response()
$res->setVary(array(
'Accept-Encoding',
));
$res->setPublic();
$res->setNotModified();
...
46. Cacheable by all caches
public function articleAction($id)
{
$res = new Response()
$res->setVary(array(
'Accept-Encoding',
));
$res->setPublic();
$res->setNotModified();
...
47. or by local only
public function articleAction($id)
{
$res = new Response()
$res->setVary(array(
'Accept-Encoding',
));
$res->setPrivate();
$res->setNotModified();
...
48. Good old 304
public function articleAction($id)
{
$res = new Response()
$res->setVary(array(
'Accept-Encoding',
));
$res->setPrivate();
$res->setNotModified();
...
51. HTTP's cache fails when dealing with really dynamic pages,
because consumers will always have to hit the origin server,
although a part of the page would be cacheable ( header and
footer, for example )
69. Evolve
Because you want your platform to extensible
Loose coupling
Because you want it to be easy to integrate with, evolve, plug
and mantain
Work less
70. Evolve
Because you want your platform to extensible
Loose coupling
Because you want it to be easy to integrate with, evolve, plug
and mantain
Work less
Because every LoC is bug-prone and our man-day is a hard-to-
scale cost