Exemplo n.º 1
0
 /**
  * Invalidate cache entries that contain any of the specified tags in their
  * tag header.
  *
  * @param array $tags Cache tags
  *
  * @return $this
  */
 public function invalidateTags(array $tags)
 {
     $tagExpression = sprintf('(%s)(,.+)?$', implode('|', array_map('preg_quote', $this->escapeTags($tags))));
     $headers = array($this->tagsHeader => $tagExpression);
     $this->invalidator->invalidate($headers);
     return $this;
 }
Exemplo n.º 2
0
 /**
  * Invalidate cache entries that contain any of the specified tags in their
  * tag header.
  *
  * @param array $tags Cache tags
  *
  * @return $this
  */
 public function invalidateTags(array $tags)
 {
     $escapedTags = array_map('preg_quote', $this->escapeTags($tags));
     if (mb_strlen(implode('|', $escapedTags)) >= $this->headerLength) {
         /*
          * estimate the amount of tags to invalidate by dividing the max
          * header length by the largest tag (minus 1 for the implode character)
          */
         $tagsize = max(array_map('mb_strlen', $escapedTags));
         $elems = floor($this->headerLength / ($tagsize - 1)) ?: 1;
     } else {
         $elems = count($escapedTags);
     }
     foreach (array_chunk($escapedTags, $elems) as $tagchunk) {
         $tagExpression = sprintf('(%s)(,.+)?$', implode('|', $tagchunk));
         $headers = array($this->tagsHeader => $tagExpression);
         $this->invalidator->invalidate($headers);
     }
     return $this;
 }
Exemplo n.º 3
0
 public function testMethodException()
 {
     $proxyClient = \Mockery::mock('\FOS\HttpCache\ProxyClient\ProxyClientInterface');
     $cacheInvalidator = new CacheInvalidator($proxyClient);
     try {
         $cacheInvalidator->invalidatePath('/');
         $this->fail('Expected exception');
     } catch (UnsupportedProxyOperationException $e) {
         // success
     }
     try {
         $cacheInvalidator->refreshPath('/');
         $this->fail('Expected exception');
     } catch (UnsupportedProxyOperationException $e) {
         // success
     }
     try {
         $cacheInvalidator->invalidate(array());
         $this->fail('Expected exception');
     } catch (UnsupportedProxyOperationException $e) {
         // success
     }
     try {
         $cacheInvalidator->invalidateRegex('/');
         $this->fail('Expected exception');
     } catch (UnsupportedProxyOperationException $e) {
         // success
     }
     try {
         $cacheInvalidator->invalidateTags(array());
         $this->fail('Expected exception');
     } catch (UnsupportedProxyOperationException $e) {
         // success
     }
 }