Skip to content

Instantly share code, notes, and snippets.

@stof
Created August 31, 2012 10:06
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 stof/3551077 to your computer and use it in GitHub Desktop.
Save stof/3551077 to your computer and use it in GitHub Desktop.
Conditional HttpCache for Drupal
<?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