Created
August 31, 2012 10:06
-
-
Save stof/3551077 to your computer and use it in GitHub Desktop.
Conditional HttpCache for Drupal
This file contains 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 | |
use Drupal\Core\DrupalKernel; | |
use Symfony\Component\HttpFoundation\Request; | |
use Symfony\Component\HttpKernel\HttpCache\Esi; | |
use Symfony\Component\HttpKernel\HttpCache\HttpCache; | |
use Symfony\Component\HttpKernel\HttpCache\Store; | |
// Build a drupal kernel | |
$kernel = new DrupalKernel() | |
$request = Request::createFromGlobals() | |
$esi = new Esi() | |
if (!$esi->hasSurrogateEsiCapability($request)) { | |
// There is no reverse proxy supporting ESI in front, so add the Symfony HttpCache | |
// this is not executed when you have Varnish in front and properly configured | |
$kernel = new HttpCache($kernel, new Store(), $esi); | |
} | |
$response = $kernel->handle($request); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment