/**
  * 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();
 }
 /**
  * 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();
 }
Beispiel #3
0
    public function testEliminateDuplicates()
    {
        $self = $this;
        $client = \Mockery::mock('\Guzzle\Http\Client[send]', array('', null))
            ->shouldReceive('send')
            ->once()
            ->with(
                \Mockery::on(
                    function ($requests) use ($self) {
                        /** @type Request[] $requests */
                        $self->assertCount(4, $requests);
                        foreach ($requests as $request) {
                            $self->assertEquals('PURGE', $request->getMethod());
                        }

                        return true;
                    }
                )
            )
            ->getMock();

        $varnish = new Varnish(array('127.0.0.1', '127.0.0.2'), 'fos.lo', $client);

        $this->assertEquals(
            2,
            $varnish
                ->purge('/c', array('a' => 'b', 'c' => 'd'))
                ->purge('/c', array('c' => 'd', 'a' => 'b')) // same request (header order is not significant)
                ->purge('/c') // different request as headers different
                ->purge('/c')
                ->flush()
        );
    }
Beispiel #4
0
    public function testPurgeHost()
    {
        $varnish = new Varnish(array('http://127.0.0.1:' . $this->getProxy()->getPort()));

        $this->getResponse('/cache.php');

        $varnish->purge('http://localhost:6181/cache.php')->flush();
        $this->assertMiss($this->getResponse('/cache.php'));
    }