Last active
November 9, 2015 13:33
-
-
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
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 | |
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