[WIP][RFC] Fastly support
Adding Fastly support. At the moment only tag invalidation. Goes with https://github.com/FriendsOfSymfony/FOSHttpCache/pull/403
will need to be updated once https://github.com/FriendsOfSymfony/FOSHttpCache/pull/451 is wrapped up
@hpatoio You ok with doing the fix-ups or would you like us to take over on it?
An additional issue: since Fastly doesn't use proxy servers for invalidating, the HttpDispatcher's approach of running through proxy servers (done in the fanOut() method) won't work.
A simple solution is to make a copy of the HttpDispatcher class and remove any mentions of servers and baseUris.
Attached example of such a class. FastlyDispatcher.txt
This would just require that the Fastly proxy client is instantiated with the FastlyDispatcher instead:
$some_example_tags = [
'product1',
'product2',
];
$httpDispatcher = new \FOS\HttpCache\ProxyClient\FastlyDispatcher();
$options = [
'service_identifier' => '...',
'authentication_token' => '...',
'soft_purge' => true,
];
$fastly = new \FOS\HttpCache\ProxyClient\Fastly($httpDispatcher, $options);
$cacheInvalidator = new \FOS\HttpCache\CacheInvalidator($fastly);
$cacheInvalidator->invalidateTags($some_example_tags)->flush();
Additionally, since Fastly uses space separated surrogate keys, the default comma-separated tag header formatter won't work. Again it may make sense to create a new class for Fastly.
Example implementation:
<?php
namespace FOS\HttpCache\TagHeaderFormatter;
class FastlyTagHeaderFormatter implements TagHeaderFormatter
{
const FASTLY_TAG_HEADER = 'Surrogate-Key';
const FASTLY_TAG_HEADER_GLUE = ' ';
/**
* @var string
*/
private $headerName = self::FASTLY_TAG_HEADER;
/**
* @var string
*/
private $glue = self::FASTLY_TAG_HEADER_GLUE;
/**
* {@inheritdoc}
*/
public function getTagsHeaderName()
{
return $this->headerName;
}
/**
* {@inheritdoc}
*/
public function getTagsHeaderValue(array $tags)
{
return implode($this->glue, $tags);
}
}
From there its a simple matter of overriding the service id in the user Symfony application:
services:
fos_http_cache.tag_handler.header_formatter:
class: FOS\HttpCache\TagHeaderFormatter\FastlyTagHeaderFormatter