/**
  * Clear all cache in Varnish for given tags
  *
  * @param array $tags
  * @param string $domain The domain to flush, e.g. "example.com"
  * @return void
  */
 public function banByTags(array $tags, $domain = NULL)
 {
     if (count($this->settings['ignoredCacheTags']) > 0) {
         $tags = array_diff($tags, $this->settings['ignoredCacheTags']);
     }
     if ($domain !== NULL) {
         $this->varnishProxyClient->setDefaultBanHeader(ProxyClient\Varnish::HTTP_HEADER_HOST, $domain);
     }
     $this->tagHandler->invalidateTags($tags);
     if ($domain !== NULL) {
         $this->varnishProxyClient->setDefaultBanHeader(ProxyClient\Varnish::HTTP_HEADER_HOST, ProxyClient\Varnish::REGEX_MATCH_ALL);
     }
     $this->systemLogger->log(sprintf('Cleared varnish cache for tags "%s"%s', implode(',', $tags), $domain ? ' for domain "' . $domain . '"' : ''));
     $this->execute();
 }
Esempio n. 2
0
    public function testBanHeaders()
    {
        $varnish = new Varnish(array('http://127.0.0.1:123'), 'fos.lo', $this->client);
        $varnish->setDefaultBanHeaders(
            array('A' => 'B')
        );
        $varnish->setDefaultBanHeader('Test', '.*');
        $varnish->ban(array())->flush();

        $requests = $this->getRequests();
        $this->assertCount(1, $requests);
        $this->assertEquals('BAN', $requests[0]->getMethod());

        $headers = $requests[0]->getHeaders();
        $this->assertEquals('.*', $headers->get('Test'));
        $this->assertEquals('B', $headers->get('A'));
        $this->assertEquals('fos.lo', $headers->get('Host'));
    }
 /**
  * Clear all cache in Varnish for given tags
  *
  * @param array $tags
  * @param string $domain The domain to flush, e.g. "example.com"
  * @return void
  */
 public function banByTags(array $tags, $domain = NULL)
 {
     if (count($this->settings['ignoredCacheTags']) > 0) {
         $tags = array_diff($tags, $this->settings['ignoredCacheTags']);
     }
     /**
      * Sanitize tags
      * @see \TYPO3\TypoScript\Core\Cache\ContentCache
      */
     foreach ($tags as $key => $tag) {
         $tags[$key] = strtr($tag, '.:', '_-');
     }
     // Set specific domain before invalidating tags
     if ($domain !== NULL) {
         $this->varnishProxyClient->setDefaultBanHeader(ProxyClient\Varnish::HTTP_HEADER_HOST, $domain);
     }
     $this->tagHandler->invalidateTags($tags);
     // Unset specific domain after invalidating tags
     if ($domain !== NULL) {
         $this->varnishProxyClient->setDefaultBanHeader(ProxyClient\Varnish::HTTP_HEADER_HOST, ProxyClient\Varnish::REGEX_MATCH_ALL);
     }
     $this->logger->log(sprintf('Cleared Varnish cache for tags "%s"%s', implode(',', $tags), $domain ? ' for domain "' . $domain . '"' : ''));
     $this->execute();
 }