Skip to content

Instantly share code, notes, and snippets.

@odino
Created May 2, 2014 17:40
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 odino/b3fdacceaa0cce65fbce to your computer and use it in GitHub Desktop.
Save odino/b3fdacceaa0cce65fbce to your computer and use it in GitHub Desktop.
<?php
namespace My\Namespace;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface;
class CacheMiddleware implements HttpKernelInterface
{
/**
* Constructor
*
* @param HttpKernelInterface $app
* @param array $cacheConfig
*/
public function __construct(HttpKernelInterface $app, array $cacheConfig)
{
$this->app = $app;
$this->cacheConfig = $cacheConfig;
}
/**
* {@inheritdoc}
*/
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
{
$response = $this->app->handle($request, $type, $catch);
$cacheType = $response->header->get('X-Cache-Type')
if (isset($this->cacheConfig[$cacheType])) {
$response->headers->addCacheControlDirective($this->cacheConfig[$cacheType]);
}
return $response;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment