Skip to content

Instantly share code, notes, and snippets.

@ThijsFeryn
Last active November 9, 2015 13:33
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 ThijsFeryn/5f3b908505e71dca677a to your computer and use it in GitHub Desktop.
Save ThijsFeryn/5f3b908505e71dca677a to your computer and use it in GitHub Desktop.
A page built using Symfony Components containing 3 content blocks: the main content block with a TTL of 10 seconds and 2 content blocks loaded via ESI. The first one has a TTL of 20 seconds, the second one doesn't cache
<?php
require_once __DIR__.'/vendor/autoload.php';
use Symfony\Component\HttpKernel\HttpCache\Esi;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
$esi = new Esi;
$request = Request::createFromGlobals();
$response = new Response();
$content = '<h1>This pages refreshes every 10 seconds</h1>';
$content .= date("Y-m-d H:i:s").'<br/>';
if($esi->hasSurrogateEsiCapability($request)){
$content .= $esi->renderIncludeTag($request->getBasePath().'/block_with_20s_cache',null,false).'<br />';
$content .= $esi->renderIncludeTag($request->getBasePath().'/block_wit_no_cache',null,false).'<br />';
}
$response->setContent($content);
$esi->addSurrogateControl($response);
$response->setSharedMaxAge(10);
$response->send();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment